Search code examples
c++multithreadingqtsignals-slots

Slot not receiving Signal in QT application


I have a bit of a strange situation wherein I have a worker thread doing it's thing and then emitting a signal to callback the GUI thread to close a dialog box. Can someone please explain why this works:

WorkerThread:

[Header]
signals:
    void writeComplete(void);

[Source]
void startWorkerThread()
{
    // do some stuff in boost::thread
    emit writeComplete();
}

MainWindow subclass:

burnDialog = new QProgressDialog("Writing to disc", "", 0, 0);
burnDialog ->setCancelButton(0);
QWidget::connect( discHandler.get(), SIGNAL(writeComplete()), burnDialog, SLOT(close()) );
QWidget::connect( discHandler.get(), SIGNAL(writeComplete()), this, SLOT(close()) );
burnDialog->open();
discHandler->startWorkerThread();

but this doesn't:

MainWindow subclass: [Header] public slots: void closeWithDialog(void);

[Source]
burnDialog = new QProgressDialog("Writing to disc", "", 0, 0);
QWidget::connect( discHandler.get(), SIGNAL(writeComplete()), this, SLOT(closeWithDialog()) );
burnDialog ->setCancelButton(0);
burnDialog->open();
discHandler->startWorkerThread();

void closeWithDialog()
{
    burnDialog->close();
    close();
}

Solution

  • Feeling like a ... I didn't put Q_OBJECT in the header file. I assumed that the fact that the subclass inherited QMainWindow that the Q_OBJECT interface would also be implicity inherited. But it wasn't... Thanks for the help anyway guys!