C++ (Qt)void ClassName::doWork(){... if (!accessManager) { accessManager = new QNetworkAccessManager; connect(accessManager, SIGNAL(finished(QNetworkReply*)), SLOT(onManagerReply(QNetworkReply*))); }... accessManager->get(...);}
C++ (Qt) ClassName *worker = new ClassName; QThread *workerThread = new QThread(this); //object params... //signals/slots connect(worker, SIGNAL(workFinished()), workerThread, SLOT(quit()));... //thread signals/slots connect(workerThread, SIGNAL(started()), worker, SLOT(doWork())); connect(workerThread, SIGNAL(finished()), SLOT(onWorkerThreadFinished())); //moving object to thread worker->moveToThread(workerThread); workerThread->start();
QObject: Cannot create children for a parent that is in a different thread.(Parent is QNetworkAccessManager(0x125edf20), parent's thread is QThread(0x16acca68), current thread is QThread(0x125adce8)
C++ (Qt)void ClassName::doWork(){... accessManager = new QNetworkAccessManager( this );}
C++ (Qt)connect(worker, SIGNAL(userScanned(...)), SLOT(onWorkerUserScanned(...)));
C++ (Qt)void SearchWidget::onWorkerUserScanned(...){ ClassName *w = qobject_cast<ClassName *>(sender()); if (!w) return;... if (...) { w->setSomething(...); w->doWork(); } else { ... w->stopWork(); }}