Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

qt

I'm trying to send a queued signal that uses a uint8_t as a parameter.

I get this error:

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

I have added qRegisterMetaType<uint8_t>(); as the first line of main() and I also added Q_DECLARE_METATYPE(uint8_t) to a header that every file includes.

I still get the same error. What's up with that? Is it some weird thing specifically with basic types, because it works fine for my custom classes.

like image 991
Timmmm Avatar asked Dec 18 '22 05:12

Timmmm


1 Answers

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

like image 117
Xplatforms Avatar answered Dec 24 '22 01:12

Xplatforms