title: Parallel threads, QT
body: <p>I'm newbie at QT and I've not a lot of expirience with working threads. 
  I've readed many guides about threads and found that there are at least 3 ways to work with threds. I'm interested in one of them, there are my example: I've made class and I'm trying to use its function in thread.</p>
  
  <p>.h</p>
  
  <pre><code>#ifndef IDENTIFICATOR_H_
  #define IDENTIFICATOR_H_
  #include &lt;QtCore&gt;
  #include &lt;QCoreApplication&gt;
  
  class identificator:public QObject {
  Q_OBJECT
  public:
      identificator(int i);
      virtual ~identificator();
  private:
  int id;
  private slots:
  void printID();
  public:
  void setID(int i);
  int getID();
  signals:
  void finished();
  };
  </code></pre>
  
  <p>.cpp</p>
  
  <pre><code>#include "identificator.h"
  #include &lt;stdio.h&gt;
  #include &lt;QDebug&gt;
  identificator::identificator(int i) {
  id=i;
  }
  
  identificator::~identificator() {
      // TODO Auto-generated destructor stub
  }
  void identificator::setID(int i)
  {
  id=i;
  }
  int identificator::getID()
  {
  return id;
  }
  void identificator::printID()
  {
      for(int i=0;i&lt;10;i++)
      {
  qDebug()&lt;&lt;" "&lt;&lt;this-&gt;getID()&lt;&lt;" "&lt;&lt;i&lt;&lt;" "&lt;&lt;this-&gt;thread();
      }emit finished();
  
  }
  </code></pre>
  
  <p>and main.cpp</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
      printf("Hello\n");
      identificator *first=new identificator(0);
      identificator *second=new identificator(0);
      QThread *thread1=new QThread;
      QThread *thread2=new QThread;
      first-&gt;setID(3);
      second-&gt;setID(4);
      first-&gt;moveToThread(thread1);
      second-&gt;moveToThread(thread2);
      QObject::connect(thread1, SIGNAL(started()), first, SLOT(printID()));
      QObject::connect(thread2, SIGNAL(started()), second, SLOT(printID()));
      QObject::connect(first, SIGNAL(finished()), thread1, SLOT(quit()));
      QObject::connect(second, SIGNAL(finished()), thread2, SLOT(quit()));
      thread1-&gt;start();
      thread2-&gt;start();
      return a.exec();
  }
  </code></pre>
  
  <p>I thought, that in console output there will be something like:
  3
  4
  3
  3
  3
  4
  4
  but I have only
  4
  4
  4
  4
  4
  4</p>
  
  <p>I'm very need in Your help, thanks!</p>
  
  <hr>
  
  <hr>
  
  <p>I have next output:</p>
  
  <pre><code>Hello
  4 0 QThread(0x8053268)
  3 0 QThread(0x8053250)
  3 1 QThread(0x8053250)
  3 2 QThread(0x8053250)
  3 3 QThread(0x8053250)
  3 4 QThread(0x8053250)
  3 5 QThread(0x8053250)
  3 6 QThread(0x8053250)
  3 7 QThread(0x8053250)
  3 8 QThread(0x8053250)
  3 9 QThread(0x8053250)
  4 1 QThread(0x8053268)
  4 2 QThread(0x8053268)
  4 3 QThread(0x8053268)
  4 4 QThread(0x8053268)
  4 5 QThread(0x8053268)
  4 6 QThread(0x8053268)
  4 7 QThread(0x8053268)
  4 8 QThread(0x8053268)
  4 9 QThread(0x8053268)
  </code></pre>