QObject::connect: Cannot queue arguments of type "xxx",(Make sure "xxx" is registed using qRegisterM

来源:互联网 发布:公文流转软件 编辑:程序博客网 时间:2024/06/03 04:04

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

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

阅读全文
0 0
原创粉丝点击