Serial port reading with QSerialPort : No such slot QObject...
-
Hello everyone,
I'm trying to read data sent on a serial port using the QSerialPort library. The data are values that come from an Arduino card. After some research, I did the following blockcode which sets the serial port to read and then a signal connected to a slot to acquire the data. The'PortListener' function is then called in the main.
PortListener::PortListener(const QString &portName) { this->port = new QSerialPort(); port->open(QIODevice::ReadWrite); port->setPortName(portName); port->setBaudRate(QSerialPort::Baud9600); port->setDataBits(QSerialPort::Data8); port->setParity(QSerialPort::NoParity); port->setStopBits(QSerialPort::OneStop); port->setFlowControl(QSerialPort::NoFlowControl); connect(port, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); } void PortListener::readyReadSlot() { while(!port->atEnd()){ QByteArray data = port->readAll(); qDebug() << "message :" << data; } }
After running the program, I get an error message like "QObject::connect: No such slot QObject::readyReadSlot()" which seems to mean that no data is sent on the serial port. However, I did some tests with the examples provided by the QextSerialPort library and I am receiving the data well so the error will not come from there. I would still like to use QSerialPort.
Does anyone have any idea where the problem might come from?
-
hi @Quintinius said in Serial port reading with QSerialPort : No such slot QObject...:
you're using the olf (Qt4) syntax,connect(port, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
using that synatx, you must mark functions that are slots, with the slots macro in the header file. Or it won't work at all
public slots: void readyReadSlot();
-
@Quintinius said in Serial port reading with QSerialPort : No such slot QObject...:
"QObject::connect: No such slot QObject::readyReadSlot()"
Error is saying that the class QObject has no
methodpublic slot called readyReadSlotI still don't know why you have this error, but please try to use the new Signal/Slot syntax
connect(port, &QSerialPort::readyRead, this, &PortListener::readyReadSlot);