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://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