Suppose I have a class cWorker : public QObject
that contains a SLOT listen()
. This object is moved to a separate thread.
The main window contains a class GLWidget : public QGLWidget
, that has a SIGNAL request()
How do I connect
the signal-slot across the two threads? It should be straight forward but I could not find any example code on that. Thanks.
int main(int argc, char *argv[])
{
cWorker* worker = new cWorker();
QThread* thread = new QThread;
worker->moveToThread(thread);
QObject::connect(thread, SIGNAL(started()), worker, SLOT(work()) );
thread->start();
QApplication a(argc, argv);
MainWindow w;
GLWidget *my_gl_widget = w.findChild<GLWidget*>("widget");
// THIS DOESN'T WORK
QObject::connect(my_gl_widget, SIGNAL( request() ), worker, SLOT( listen() ));
w.show();
return a.exec();
}