QSerialPort crash on write()
Unsolved
General and Desktop
-
Hello,
I find that this code runs fine in Debug mode but in Release mode causes my program to crash a few seconds after opening.
If remove the line that writes to the serial port then it doesn't crash.
I can't figure out why it is crashing!
MyClass::MyClass() { // Serial port connection m_serialPort = new QSerialPort(this); connect(m_serialPort, &QSerialPort::readyRead, this, &MyClass::readSerialData); openSerialPort(); } void MyClass::openSerialPort() { QString portName = ""; const QList<QSerialPortInfo> infos = QSerialPortInfo::availablePorts(); for (const QSerialPortInfo &info : infos) { if (info.isBusy() == false) { portName = info.portName(); } } m_serialPort->setPortName(portName); if (m_serialPort->open(QIODevice::ReadWrite)) { // connected } else { qWarning() << "Cannot open serial port"; } m_serialPort->write("TESTWRITE", 9); }
-
Hi,
Can you show a stack trace ?
-
Indeed, it's harder. I somehow missed the "Release" part...
On a side note, it's pretty unusual to call write if the port opening failed.