Reputation: 411
I'm trying to use QObject::connect
to start a slot from after a thread finishes.
My class definition is:
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;
};
I tried the following code:
connect(&watcher, SIGNAL(finished()), this, SLOT(show_box()));
But when I run the compiled binary it says:
QObject::connect: No such slot QWidget::show_box()
I've also tried
QFutureWatcher<void> *watcher;
connect(watcher, &QFutureWatcher<void>::finished, this, &Test::show_box);
But it exits with a segmentation fault.
Upvotes: 2
Views: 1195
Reputation: 560
Missing Q_OBJECT
inside Test
.
What does the Q_OBJECT macro do? Why do all Qt objects need this macro?
If you don't have it, signals/slots don't work.
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;
};
Upvotes: 3