Reputation: 3429
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();
}
Upvotes: 1
Views: 3653
Reputation: 3429
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!
Upvotes: 3
Reputation: 2007
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()) );
Upvotes: 0