void myThread::run(){ emit num();}
Thread threadNumA(new ParameterizedThreadStart(numA); // void numA()Thread threadNumB(new ParameterizedThreadStart(numB); // void numB()threadNumA.Start();threadNumB.Start();//Ждём пока они не finishedthreadNumA.Join();threadNumB.Join();
C++ (Qt)#include <QThread> typedef void (*RunProc)( void ); class MyThread : public QThread { public: MyThread( RunProc proc ) : mProc(proc) {} void run( void ) { mProc(); } RunProc mProc;}; void MyRun1( void ){ // do something} void MyRun2( void ){ // do something} int main(){ MyThread thread1(MyRun1); MyThread thread2(MyRun2); thread1.start(); thread2.start(); thread1.wait(); thread2.wait(); return 0;}
C++ (Qt)void thead_func() { /* ... */} int main() { std::thread thread(thread_func); thread.join(); return 0;}
#include <QThread> typedef void (*RunProc)( void ); class MyThread : public QThread { public: MyThread( RunProc proc ) : mProc(proc) {} void run( void ) { mProc(); } RunProc mProc;}; void MyRun1( void ){ // do something} void MyRun2( void ){ // do something} int main(){ MyThread thread1(MyRun1); MyThread thread2(MyRun2); thread1.start(); thread2.start(); thread1.wait(); thread2.wait(); return 0;}
C++ (Qt)struct CCalculator { virtual void DoCalc( void ) = 0;};
C++ (Qt)class MyThread : public QThread { public: MyThread( CCalculator * calc ) : mCalc(calc) {} void run( void ) { mCalc->DoCalc(); } CCalculator * mCalc;};
C++ (Qt)struct MyCalc1 : public CCalculator { MyCalc1( Alfavit * a ) : mAlpha(a) {} void DoCalc( void ) { mAlpha->DoSomething(); } Alfavit * mAlpha;};
C++ (Qt)MyCalc1 calc1(alphavit);MyThread thread1(&calc1);thread1.start();thread1.wait();
C++ (Qt)struct Alphavit : public CCalculator { void DoCalc( void );};