Home > Mobile >  Qt - moveToThread multithreading ()
Qt - moveToThread multithreading ()

Time:12-09

Under the Qt, create QObject subclass, use moveToThread () method, is introduced into the child thread processing;
For example:
Class A: public QObject
{
//such as implementation tcpSocket receiving and sending, and data processing, etc.,,,
}
At this point, the need to use this class to create two threads, and process data respectively;
For example, a header file that:
A * a1.
A * a2;

Create a thread:
A1=new A;//do not specify a parent class
Thread1 QThread *=new QThread (this);
A1 - & gt; MoveToThread (thread1);
Thread1 - & gt; start();
//realize multi-threaded processing data, through signals and slots,,

A2=new A;//do not specify a parent class
Thread2 QThread *=new QThread (this);
A2 - & gt; MoveToThread (thread2);
Thread2 - & gt; start();
//realize multi-threaded processing data, through signals and slots,,

Q 1. The above way, can realize the processing of the same class slot function called, to deal with two child thread under a1 and a2 data? I how sometimes a1 thread can handle, a2 thread can receive the socket data, but not to deal with? The right way to achieve two child thread is how?

Q 2. In the class A, if you want to put the child thread processing, whether also needs through to A signaling link A slot function; That is called directly in the class A class method function, whether in the main thread?

Thank you very much!

  •  Tags:  
  • Qt
  • Related