Qt QObject::connect: Cannot queue arguments of type ‘uint16_t‘

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值