1

我有一个奇怪的情况,我有一个工作线程在做这件事,然后发出一个信号来回调 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();
}
4

2 回答 2

3

感觉像...我没有放入Q_OBJECT头文件。我假设子类继承QMainWindowQ_OBJECT接口也将被隐式继承的事实。但它不是......无论如何,谢谢你们的帮助!

于 2012-06-18T11:53:40.850 回答
0

这是不起作用的情况下的故障线路:

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

您正在SLOTburnDialog实例分配一个,这意味着closeWithDialog()方法必须属于QProgressDialog类。QProgressDialog没有这样的方法。您应该检查控制台是否有以下消息:

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

把上面的故障线改成如下:

QWidget::connect( discHandler.get(), SIGNAL(writeComplete()), this,
                  SLOT(closeWithDialog()) );
于 2012-06-15T10:10:48.187 回答