1

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();
}
Sonoman
  • 3,379
  • 9
  • 45
  • 61

2 Answers2

3

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!

Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
Sonoman
  • 3,379
  • 9
  • 45
  • 61
0

Here is the faulty line in doesn't work case:

QWidget::connect( discHandler.get(), SIGNAL(writeComplete()), burnDialog,
                  SLOT(closeWithDialog()) );

You're assigning a SLOT to burnDialog instance, that means closeWithDialog() method must be of QProgressDialog class. QProgressDialog don't have any method like that. You should check your console for following message:

Object::connect: No such slot QProgressDialog::closeWithDialog()

Change above faulty line into following:

QWidget::connect( discHandler.get(), SIGNAL(writeComplete()), this,
                  SLOT(closeWithDialog()) );
Ammar
  • 1,947
  • 14
  • 15
  • THanks for catching that muck up. Unfortunately that was just an error of Ctrl+C & Ctrl+V :p. In the actual code, I do have `QWidget::connect( discHandler.get(), SIGNAL(writeComplete()), this, SLOT(closeWithDialog()) );` – Sonoman Jun 15 '12 at 10:15
  • Ohh great.. :) Well, you should `EDIT` the question right away. Also, I hope you checked you're not getting any `connect` failed message in console. – Ammar Jun 15 '12 at 11:01