title: c++ qthread starting 2 threads concurrently
body: <p>I have two threads One and Two. defined by their respective classes in the header file.I want to start the second thread when the first thread is started.  creating and starting the second thread in the constructor of the first produced unexpected result.
  my header file <strong>"header.h"</strong></p>
  
  <pre><code>#ifndef HEADER
  #define HEADER
  #include &lt;QtGui&gt;
  class One:public QThread
  {
  public:
      One();
      void run();
  
  };
  
  class Two:public QThread
  {
  public:
      Two();
      void run();
  };
  #endif
  </code></pre>
  
  <p>my class file <strong>"main.cpp"</strong></p>
  
  <pre><code>#include "header.h"
  #include&lt;iostream&gt;
  using namespace std;
  
  One::One()
  {
  /* the output just hangs at thread two and does not get to thread one run */
  Two b;
  b.start();
  b.wait();
  
  }
  void One::run()
  {
      cout&lt;&lt;"One run\n";
      int i=0;
      for(;;)
      {
  
          i++;
          cout&lt;&lt;"+++ "&lt;&lt;i&lt;&lt;endl;
          if(i==10)
              break;
          sleep(3);
      }
  }
  
  Two::Two()
  {
  
  }
  void Two::run()
  {
  
      cout&lt;&lt;"Two run\n";
      int i=0;
      for(;;)
      {
  
          i--;
          cout&lt;&lt;"----- "&lt;&lt;i&lt;&lt;endl;
          sleep(3);
      }
  }
  int main(int argc,char* argv[])
  {
      One a;
     // Two b;
      a.start();
     // b.start();
     a.wait();
     // b.wait();
      return(0);
  
  }
  </code></pre>
  
  <p>This is the working code of how i expect the output to run. </p>
  
  <blockquote>
    <p><strong>Edit: changed the code so that now
    both the threads are properly
    independent</strong></p>
    
    <p><strong>How do i start the second thread along with the first thread, without explicitly  calling two in main i.e .</strong> </p>
  </blockquote>
  
  <pre><code>int main(int argc,char* argv[])
  {
       One a;
      Two b;
      a.start();
      b.start();
      a.wait();
      b.wait();
     return(0);
  }
  </code></pre>
  
  <blockquote>
    <p>The invoking and handling of thread two should be done by thread one..</p>
  </blockquote>