QThread signals wont work
I calculating model and without about 16 threads Im post for few hours. My problem is that receiving function is not called.
@ QThread* thread = new QThread();
FaceWorker* worker = new FaceWorker(vertexs, i); worker->moveToThread(thread); connect(thread, &QThread::finished, worker, &FaceWorker::deleteLater); connect(this, &Face::operate, worker, &FaceWorker::doWork); connect(worker, &FaceWorker::resultReady, this, &Face::handleResults); thread->start();@
handleResults is not called
@void Face::handleResults(int threadID)
qDebug() << "thread" << threadID << "has done its work";
qDebug() << "emiting results" << threadNumber;
emit resultReady( threadNumber);
This is called ok
class Face : public QObject
Face(QObject* parent = NULL);
void handleResults(int threadID);
class FaceWorker : public QObject
FaceWorker(int threadID, QObject* parent = NULL);
void resultReady(int threadID);
Sorry for formatting.. iPad
Thanks for ideas and help
The code looks OK. If the debug message in doWork() is printed, than handleResults() should be called. But to be sure, you can check that the connections are really made:
if ( ! connect(...) )
//Houston, we have a problem!
What is the second parameter 'i' passed to the FaceWorker constructor? If i is the parent, this is not the right thing to do because you "can't":http://doc.qt.io/qt-5/qobject.html#moveToThread move an object with a parent to another thread. I don't know whether this has anything to do with your problem.
Connects were ok... I just made it another way, bit hacky but I didnt have time for solving it. Other connections were working like MainWindow, OpenGLWidget, etc.