我有一个奇怪的情况,我有一个工作线程在做这件事,然后发出一个信号来回调 GUI 线程以关闭一个对话框。有人可以解释为什么这样做:
工作线程:
[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 子类:[Header] 公共插槽: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();
}