参考此网址:http://www.bubuko.com/infodetail-667189.html
一:
在线程中通过信号和槽函数传递信息的时候,由于用到了自己定义的参数结构:QHash<int , pMsg>,于是在发生信号传递的时候出现了报错:
QObject::connect: Cannot queue arguments of type “QHash<int , pMsg>”,(Make sure “QHash<int , pMsg>” is registed using qRegisterMetaType().)
查找到原因为:
线程中信号和槽函数的传递,参数是默认放到队列中去的,但是这个自定义的参数结构,不是QT自带的参数结构,不能识别。
解决方法有两点:
(1)将不识别的参数结构进行注册,让QT能够识别。
A 包含头文件:#include <QMetaType>
B 在构造的类的构造函数中调用其方法完成注册:qRegisterMetaType<QList<float> >(“QList<float>”);
(2)直接调用对方槽函数,不保存参数,直接传递。
connect(master,SIGNAL(send_data(int,QList<float>,bool,bool)),this,SLOT(slot_dataChange(int,QList<float>,bool,bool)),Qt::DirectConnection);
此种方法未测试,且官方认为这样做有风险,不推荐。
connect: Cannot queue arguments of type "xxx",(Make sure "xxx" is registed using qRegisterMetaType()
最新推荐文章于 2024-08-10 14:13:51 发布