我正在尝试使用QObject::connect在线程结束后启动一个插槽。
我的类定义是:
class Test : public QWidget
{
public:
Test(QWidget *parent=0);
private slots:
void do_work();
void show_box();
private:
QFuture<void> work_thread;
QFutureWatcher<void> watcher;
};我尝试了以下代码:
connect(&watcher, SIGNAL(finished()), this, SLOT(show_box()));但当我运行编译后的二进制文件时,它显示:
QObject::connect: No such slot QWidget::show_box()我也试过
QFutureWatcher<void> *watcher;
connect(watcher, &QFutureWatcher<void>::finished, this, &Test::show_box);但它退出时会出现分段错误。
发布于 2015-12-07 08:27:28
Test中缺少Q_OBJECT。
What does the Q_OBJECT macro do? Why do all Qt objects need this macro?
如果你没有它,信号/插槽就不能工作。
class Test : public QWidget{
Q_OBJECT
public:
Test(QWidget *parent=0);
private slots:
void do_work();
void show_box();
private:
QFuture<void> work_thread;
QFutureWatcher<void> watcher;
};https://stackoverflow.com/questions/34124487
复制相似问题