qobject_cast没有Q_OBJECT宏错误

问题描述 投票:0回答:1

我有一个由QFutureWatcher触发的插槽。我正在试图让发送者获得结果

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

但继续得到

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

我不确定这里有什么问题,这些都是Qt内置类型,所以我做错了什么?

c++ qt casting
1个回答
0
投票

你必须将Q_OBJECT放在类定义中,如下所示:

class MyClass : public QObject
{
    Q_OBJECT
 // ^^^^^^^^^^
public:
    MyClass();
/*...*/
}
© www.soinside.com 2019 - 2024. All rights reserved.