Qt 无法对类型"uint8_t"的参数进行排队,即使使用 qRegisterMetaType 也是如此

Qt Cannot queue arguments of type 'uint8_t' even with qRegisterMetaType

本文关键字:排队 qRegisterMetaType 类型 uint8 参数 Qt      更新时间:2023-10-16

我正在尝试发送一个使用uint8_t作为参数的排队信号。

我收到此错误:

QObject::connect: Cannot queue arguments of type 'uint8_t'
(Make sure 'uint8_t' is registered using qRegisterMetaType().)

我添加了qRegisterMetaType<uint8_t>();作为main()的第一行,并且还Q_DECLARE_METATYPE(uint8_t)添加到每个文件都包含的标头中。

我仍然收到同样的错误。这是怎么回事?是不是专门针对基本类型的一些奇怪事情,因为它适用于我的自定义类。

uint8_tunsigned chartypedef。 你可以使用Qt的typedef来表示无符号的char:quint8,你不需要注册它。任何具有公共默认构造函数、公共副本构造函数和公共析构函数的类或结构都可以在QMetaType中注册。你的uint8_t是原子的,你不需要注册它,只需在Qt中使用适当的typedef即可。 无论如何,如果您想注册该类型以便它可以被QMetaProperty使用,或者QueuedConnections让它正确:

qRegisterMetaType<uint8_t>("uint8_t");

有关QtMeta系统如何工作的更多信息,请阅读Qt的文档:doc.qt.io/qt-5/qmetatype.html