我有一种奇怪的情况,我有一个工作线程在执行此操作,然后发出一个信号以回调GUI线程以关闭对话框。有人可以解释一下为什么这样工作:

WorkerThread:

[Header]
signals:
    void writeComplete(void);

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

MainWindow子类:
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();

但这不是:

MainWindow子类:
[标题]
公共(public)插槽:
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();
}

最佳答案

感觉就像...我没有在头文件中放入Q_OBJECT。我假设子类继承了QMainWindow,而Q_OBJECT接口(interface)也将隐式继承。但这不是……谢谢你们的帮助!

07-24 14:15