title: QThread passing data to and from
body: <p>I will try to explain what my program used to do and what I am tring to change:</p>
  
  <p>I had this function that ran on a button click from the the main thread in class MainWindow : public QMainWindow :</p>
  
  <p>The function looks like this and is specified inside another file:</p>
  
  <pre><code>void MakeMeshStructure(MeshStructureLayers layers,
                        Handle_AIS_InteractiveContext theContext,
                        Handle_TDocStd_Document aDoc,
                        MyMesh &amp;mesh,
                        int detail_vertex,
                        double insulation_thickness,
                        OpenMesh::VPropHandleT&lt;MyMesh::Scalar&gt; _max_beam_offset);
  }
  </code></pre>
  
  <p>What it does is: it works on mesh and creates geometry for every vertex, face and edge of the mesh. This geometry gets displayed with theContext. This process takes very long (30 min) and blocks the gui. </p>
  
  <p>What I would like to do is to have as many threads as QThread::idealThreadCount() and to free the gui when it computes and make it faster. (Is this the right thinking?)</p>
  
  <p>I would like to divide my mesh into equal parts and pass this range of vertices to my function (above) to only work with one vertex range for a seperate tread. </p>
  
  <p>I have a problem to figure out how to pass this data around and to make it thread safe. 
  I know its alot of code but here is my attempt at solving it:</p>
  
  <p><a href="http://pastebin.com/u/mzagar" rel="nofollow">http://pastebin.com/u/mzagar</a></p>
  
  <p>The problem is getting all the data around in the right way and getting the threads to work. Where do I have to use mutexes. On every data that can get writen at the time of the thread work by the mainthread? Very confused. ty</p>
  
  <p>edit:</p>
  
  <p>I edited my code: <a href="http://pastebin.com/u/mzagar" rel="nofollow">http://pastebin.com/u/mzagar</a>
  I made a struct cadData to pass the data around. This is how I start threads:</p>
  
  <pre><code>connect(this, SIGNAL(startMake1(cadData)), cThreads.at(0), SLOT(MakeMesh(cadData)));
  //...
  cThreads.at(0)-&gt;moveToThread(threads.at(0));
  //...
  threads.at(0)-&gt;start();
   //...
  emit startMake1(aCadDatas.at(0));
   //...
  </code></pre>
  
  <p>The problem is threads dont seem to work at the same time and also the gui freezes. Process goes in like this:</p>
  
  <ul>
  <li>GUI freezes</li>
  <li>things in thread 1 get done</li>
  <li>things in thread 1 get done again</li>
  <li>things in thread 2 get done</li>
  <li>things in thread 2 get done again</li>
  <li>...</li>
  <li>GUI unfreezes</li>
  </ul>
  
  <p>Any ideas why?</p>
  
  <p>edit2:</p>
  
  <p>I removed the multiple runs of the same thread by moving this to the class constructor:</p>
  
  <pre><code>connect(this, SIGNAL(startMake1(cadData)), cThreads.at(0), SLOT(MakeMesh(cadData)));
  //...
  cThreads.at(0)-&gt;moveToThread(threads.at(0));
  //...
  threads.at(0)-&gt;start();
  </code></pre>