码迷,mamicode.com
首页 > Web开发 > 详细

QObject::connect: Cannot queue arguments of type "xxx",(Make sure "xxx" is registed using qRegisterMetaType().)原因及解决方法

时间:2015-03-11 10:42:19      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

在线程中通过信号和槽函数传递信息的时候,由于用到了自己定义的参数结构: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< QHash<int , pMsg> >("QHash<int , pMsg>");

 

(2)直接调用对方槽函数,不保存参数,直接传递。

connect(pLink->module,SIGNAL(sendReportToMainWithHash(QHash<int,pMsg>,QString)),this,SLOT(receiveReportFromIecServiceWithHash(QHash<int,pMsg>,QString))Qt::DirectConnection);

此种方法未测试,且官方认为这样做有风险,不推荐。

QObject::connect: Cannot queue arguments of type "xxx",(Make sure "xxx" is registed using qRegisterMetaType().)原因及解决方法

标签:

原文地址:http://www.cnblogs.com/spyhooky/p/4329051.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!