Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qobject_cast no Q_OBJECT macro error

Tags:

c++

casting

qt

I have a slot that is triggered by a QFutureWatcher. I'm trying to cast the sender to get the results

QFutureWatcher<QPair<QImage,QString>>* QFW = qobject_cast<QFutureWatcher<QPair<QImage,QString>>*>(sender());

but keep getting

error: static assertion failed: qobject_cast requires the type to have a Q_OBJECT macro

I'm not really sure what's wrong here, these are all Qt built-in types, so what am I doing wrong?

like image 787
JLev Avatar asked Oct 29 '22 21:10

JLev


1 Answers

You have to put Q_OBJECT in the Class Definition, like this:

class MyClass : public QObject
{
    Q_OBJECT
 // ^^^^^^^^^^
public:
    MyClass();
/*...*/
}
like image 81
Dardan Iljazi Avatar answered Nov 15 '22 06:11

Dardan Iljazi