Search code examples
c++qtqtserialport

Why does qRegisterMetaType throw me an error?


I'm currently working with Qt in order to build an app able to send and receive data packets connected through QSerialPort.

For that, I have an object interfacing the communication between my app and the device.

In this class, I can call a run member function, which initiate the communication.

In that method, the connection is like this :

qRegisterMetaType<QSerialPort::SerialPortError>();
connect(this->_serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this->_parent,
SLOT(handleSerialError(QSerialPort::SerialPortError)), Qt::QueuedConnection);

Here, my problem is that no matter what I tried, I always get an error from the included file from QtCore, qglobal.h, on the line 684, referring to the first line of code where I try to register the meta type SerialPortError.

The error :

Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system.

And that's what I did! From everywhere in my code, inside the class, inside the name space, or even in global, I called that macro Q_DECLARE_METATYPE(QSerialPort::SerialPortError), but nothing was going well :/

That's my third day looking on the web to solve this error, and I'm running out of time.

I can not figure out what I'm doing wrong or misunderstanding.

Can someone help me? Have you already faced that error?

Thanks you, David


Solution

  • QSerialPort inherits QObject, so the error type enum should already be registered via Q_ENUMS. You don't need to re-register.