QObject::connect: Cannot queue arguments of typexxxxxx

出现问题背景:当一个带参数为自定义结构体PortConfig的信号发送至另一个线程的槽时,
connect(this,SIGNAL(SignalOpenPort(PortConfig)),m_pMySerialPortCom,SLOT(OpenPort(PortConfig)));
编译时不会出错,但信号出发时出现错误提示:
QObject::connect: Cannot queue arguments of type ‘PortConfig’
(Make sure ‘PortConfig’ is registered using qRegisterMetaType().)
问题原因:在线程中通过信号-槽传递信息时,参数默认放到队列中的,PortConfig是自定义的结构体,不是Qt自带的参数结构。
解决办法:将不识别的参数结构进行注册,让Qt能够识别。
包含头文件#include
在构造函数中调用其方法完成注册:
【QObject::connect: Cannot queue arguments of typexxxxxx】qRegisterMetaType(“PortConfig”); //注册PortConfig类型

    推荐阅读