I have a relatively gross device (two computers are connected through COM port) and I must get it work by QSerialPort
. The idea is simple: data is going to send from one comp to another per COM-port.
Transmitter is working okay, which was checked by side software, I have problems with receiving data. I am doing it by QSerialPort
as follows:
At first I set up port:
QSerialPort *serialport = new QSerialPort();
serialport->open(QIODevice::ReadOnly);
serialport->setPortName("COM1");
serialport->setBaudRate(QSerialPort::Baud19200);
serialport->setDataBits(QSerialPort::Data8);
serialport->setParity(QSerialPort::NoParity);
and then I am preparing to catch data like this:
connect(serialport,SIGNAL(readyRead()),this, SLOT(change_gear()) );
and in slot change_gear yet I have nothing more than: qDebug()<<"Data has beed recieved",
but this slot have not been ever executed! So, I just cannot understand what is going wrong here and why I can not read data from COM-port such easy way..
OS - Windows 8, Qt 5.8.0 MinGW 32
Try like this
QSerialPort *serialport = new QSerialPort();
serialport->setPortName("COM1");
serialport->setBaudRate(QSerialPort::Baud19200);
serialport->setDataBits(QSerialPort::Data8);
serialport->setParity(QSerialPort::NoParity);
connect(serialport,SIGNAL(readyRead()),this, SLOT(change_gear()) );
serialport->open(QIODevice::ReadOnly);
Open after port is configured and it signal is connected to slot