QObject::connect: Cannot queue arguments of type 'uint16_t'

(Make sure 'uint16_t' is registered using qRegisterMetaType().)

网上很多说遇到这种情况是由于数据结构是自定义类型,但uint16_t这个一般编译器已经帮我们定义好了,而且在非跨线程情况下都是可以用的。

但是我还是觉得可以尝试使用qint16来替代uint16_t试试,后来又在网站上看到别人的回答,更确定我的想法应该可以完美解决这个问题。于是就测试了下,果然成功了。

需要说明的是我这个是跨线程,如果非跨线程直接用uint16_t是没有报错的。

可能还有不同的解决方式,欢迎留言交流。希望可以帮到你们,有帮到你们的点个赞吧,你们的支持是我继续写博客的动力!

https://stackoverflow.com/questions/45670492/qt-cannot-queue-arguments-of-type-uint8-t-even-with-qregistermetatype/45670862

https://stackoverrun.com/cn/q/12534514

uint8_t is the typedef for unsigned char . You can use Qt's typedef for unsigned char: quint8 and you don't need to register it. Any class or struct that has a public default constructor, a public copy constructor and a public destructor can be registered in QMetaType . Your uint8_t is atomic and you don't need to register it, just use proper typedef in Qt. Anyway if you want to register that type so it can be used by QMetaProperty , or in QueuedConnections just make it right:

qRegisterMetaType<uint8_t>("uint8_t");

For more information how the QtMeta system work please read Qt's documentation for it:

uint8_t is the typedef for unsigned char. You can use Qt's typedef for unsigned char: quint8 and you don't need to register it. Any class or struct that has a public default constructor, a public copy constructor and a public destructor can be registered in QMetaType. Your uint8_t is atomic and you don't need to register it, just use proper typedef in Qt. Anyway if you want to register that type so it can be used by QMetaProperty, or in QueuedConnections just make it right:

qRegisterMetaType<uint8_t>("uint8_t");

For more information how the QtMeta system work please read Qt's documentation for it: doc.qt.io/qt-5/qmetatype.html

QObject::connect: Cannot queue arguments of type 'uint16_t'(Make sure 'uint16_t' is registered using qRegisterMetaType().)网上很多说遇到这种情况是由于数据结构是自定义类型,但uint16_t这个一般编译器已经帮我们定义好了,而且在非跨线程情况下都是可以用的。但是我还是觉得可以尝试使用qint16来替代uint16_t试试,后来又在网站上看到别人的回答,更确定我的想法应该可以完
[QT] 为解决 QObject::connect: Cannot queue arguments of type 'XXX'引发的问题:没有可用的复制构造函数或复制构造函数声明为“explicit” 定义了一个UserInfo类,没有继承自QObject,然后因为某个线程调用的信号槽调用问题导致出现 QObject::connect: Cannot queue arguments of type 'UserInfo' ... 然后引发一系列问题。 1,最初UserInfo定义成如下.
Qt 信号槽使用自定义结构体提示make sure is “XXX”registered using qRegisterMetaType()解决方法 使用命名空间 #include <QMetaType> //自定义结构体 struct STRUCT_DATA{ unsigned char byte[8]; unsigned int u16array[2]; namespace ABC{ #define REGIST_STRUCT { qRegisterMeta
当我们使用Qt自定义信号绑定信号槽,传递的参数不是int,char这些基础数据类型,比如传递一个结构体的时候,这时我们的编译器会报错“cannot queue arguments of type…”这说明我们的信号槽传递的数据类型没有进行注册,只需要注册即可。 解决方案: (注:在信号发射的.h文件中添加以下代码) 1.#include [添加头文件] 2.qRegisterMetaType<结构体名字>(“结构体名字”)[添加在构造函数中]
QObject::connect: Cannot queue arguments of type 'uint16_t' (Make sure 'uint16_t' is registered using qRegisterMetaType().) 网上很多说遇到这种情况是由于数据结构是自定义类型,但uint16_t这个一般编译器已经帮我们定义好了,而且在非跨线程情况下都是可以用的。 但是我还是觉得可以尝试使用qint16来替代uint16_t试试,后来又在网站上看到别人的回答,更确定我的想法应该可以完
C++的主要数据类型,主要分为三类:布尔型,整型(char型从本质上说,也是种整型类型,它是长度为1的整数,通常用来存放字符的ASCII码),浮点型。 (二)byte(字节)和bit(位) 普及如下: byte为字节,bit为位,1byte=8bit 这两者应用的场合不同。通常用bit来作数据传输的单位,因为物理层,数据链路层的传输对于用户是透明...
2 错误描述 在不同线程之间通过信号/槽来传递自定义数据类型QList的时候,提示错误: QObject::connect: Cannot queue arguments of type 'QList' (Make sure 'QList' is registered using qRegist private slots: void cmp_slot(QList > &strT); 为例,同一个线程,比如在同一个主线程中,是不会有问题的,但是,如果在不同的线程之中的 SIG 与 SLOT,是有问题的, 如下 代码片段: connect(&TestThread1, SIGNAL(t1_sig
1、问题描述 跨线程使用信号和槽时,如果是非const的引用传参,就会报如下的错误: QObject::connect: Cannot queue arguments of type 'QString&' (Make sure 'QString&' is registered using qRegisterMetaType().) 2、测试示例 #include <QCoreApplication> #include <QThread> #include <Q
出现问题背景:当一个带参数为自定义结构体PortConfig的信号发送至另一个线程的槽时, connect(this,SIGNAL(SignalOpenPort(PortConfig)),m_pMySerialPortCom,SLOT(OpenPort(PortConfig))); 编译时不会出错,但信号出发时出现错误提示: QObject::connect: Cannot queue ar...
今天线程传值中传容器发现子线程给主线程发信号的时候报错了,出现QObject::connect: Cannot queue arguments of type '******',该信息通过注册类型来解决容器传输报错的问题。 本文作者原创,转载请附上文章出处与本文链接。
最近在编写Qt代码的时候遇到标题上的问题,现象是:在收到一个xml字符串需要解析时,我放在线程里面处理,然后线程执行完成后将xml对应的结构体返回给主线程。在主线程的槽函数中始终接收不到,但是在子线程中emit函数是执行过的,在调试窗口中看到下面这句话:Make sure ‘SystemCfg’ is registered using qRegisterMetaType()。其中SystemCfg是emit要返回的参数。 出现这个问题的原因是:在线程中通过signal-slot传递信息时,参数默认时放到Qt
这个错误通常发生在使用Qt的信号与槽(signal-slot)机制时,参数类型是自定义类型时,Qt无法自动识别该类型,需要手动注册该类型。 在这种情况下,你需要在你的代码中调用`qRegisterMetaType`函数来注册这个类型。例如: ```cpp qRegisterMetaType<QList<QString>>("QList<QString>"); 将这行代码放在你的程序开始运行前,可以确保Qt能够正确地识别和处理该类型。 另外,如果你使用了多线程,还需要调用`moveToThread`函数将该对象移动到正确的线程中,以避免线程安全问题。