Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Problem with QSerialPort
Albert Huert last edited by
My problem is the following, I have two slot functions connected to a QPushButton that make the connection and disconnect to an arduino . And in the connection function I show a message on a display that arduino is already connected to the PC and in the other function show a message on the display when I disconnect. Then I show the functions A and B, I have reviewed and the problem I have is that the signal does not send the arduino, in the case of the connection function if I do a slot function where it has only arduino -> write(code), the message is received by the arduino. And in the case of disconnection if I remove the function close () I get the message displayed on the display.
Why is the message not sent to the arduino when I send it through the slot functions A and B?
How can I correct these functions?
Thanks for help me.
// open and configure the serialport
arduino->write("#STAR\n");//Code to show message of connection to the pc.
// give error message if not available
QMessageBox::warning(this, "Port error", "Couldn't find the Arduino!");
arduino_is_available = false;
qDebug() << "Is writable";
Gojir4 last edited by
When you write to serial port there is a delay before the data are really written on the hardware. So as you close the port after you have written it is probably closed before the data have been sent. You can add
QIODevice::waitForBytesWritten()to wait until writing has been finished. You can also use the signal
QIODevice::bytesWritten()to avoid blocking the GUI. But I don't think that's so critical here as it should be few milliseconds, except if there is an IO error.