QObject::connect: Cannot queue arguments of type 'QList' (Make sure 'QList' is

1 开发环境

Win10(64bit)

Qt5.4.2(64bit)

2 错误描述

在不同线程之间通过信号/槽来传递自定义数据类型QList<RootNode>的时候,提示错误:

[plain] view plain copy 在CODE上查看代码片派生到我的代码片
QObject::connect: Cannot queue arguments of type ‘QList’
(Make sure ‘QList’ is registered using qRegisterMetaType().)
在同一个线程中传递上述类型是没有错误的。
3 解决方法

根据参考资料[1]的提示,先包含头文件:

[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
#include
然后注册自定义类:
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
qRegisterMetaType<QList>(“QList”);
注意:其实自定义的类型只是RootNode而已,QList是Qt自带的类型。由于信号/槽中使用到const QList&类型的参数,因此需要注销QList类型!

猜你喜欢

转载自blog.csdn.net/acctrade/article/details/89326422