class CMain{... void GenerateThreads();signals: void setValue(int);};void CMain::GenerateThreads(){ for (int i = 0; i< 10; i++) { WorkThread *thread = new WorkThread(); connect(this, SIGNAL(setValue(int)), thread, SLOT(on_setValue(int))); thread->start(); emit setValue(i); }}class WorkThread: public QThread{... void run();signals: void setValue(int)slots: void on_setValue(int)};void WorkThread::run(){ CWorker *worker = new CWorker(); connect(this, SIGNAL(setValue(int)), worker, SLOT(on_setValue(int))); worker->doWork(); exec();}void WorkThread::on_setValue(int _value){ emit setValue(_value); }class CWorker{... int a; void doWork(); slots: void on_setValue(int)};void CWorker::on_setValue(int _value){ a = _value;}void CWorker::doWork(){ while (tue) { int b = a; msleep(b); } }
class CMain{... void GenerateThreads();signals: void setValue(int);};void CMain::GenerateThreads(){ for (int i = 0; i< 10; i++) { WorkThread *thread = new WorkThread(); connect(this, SIGNAL(setValue(int)), thread, SLOT(on_setValue(int))); thread->start(); QMetaObject::invokeMethod(thread, SLOT(doWork()), Qt::QueuedConnection); emit setValue(i); }}class WorkThread: public QThread{... int a;signals: void setValue(int);slots: void doWork(); void on_setValue(int);};void WorkThread::on_setValue(int _value){ a = _value;}//вариант 1void WorkThread::doWork(){ int b = a; ... QTimer::singleShot(b, this, SLOT(doWork()));} //вариант 2void WorkThread::doWork(){ while (true) { int b = a; ... msleep(b); qApp()->processEvents(); }}
C++ (Qt)bool running = true;...while( running ){}
C++ (Qt)bool stopped = false;...while( true ){ if( stopped ) break;}
while(true){ QCoreApplication::processEvent(); /// bla bla bla}