Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QSerialPort and baudrate settings
Under Windows 7, Qt 5.3 I have problems to set the baudrate of a QSerialPort:
@QSerialPort *serial = new QSerialPort(this);
setBaudRate returns true, but on some machines the baudrate is not actually set. I need to open/close the port with an external serial terminal (like RealTerm) with the desired baudrate in order to get it works.
I tried to set the baudrate before opening the port with no chance.
On other computers (same o.s., same Qt version, same USB/RS232 converter) it works fine.
I cannot understand where is the mistake.
Anyway, do you know any workaround to BE SURE the baudrate is really set? I'm puzzling over using Windows API or even launch a command-line terminal with QProcess....
The only thing I can think of would be different driver version between computers. Did you by any chance look at that ?
franku last edited by
Did you try swapping line 2. and 3. from the above?
Yes, I said:
bq. I tried to set the baudrate before opening the port with no chance.
@ franku, a QSerialPort needs to be opened first, then you do the settings.
According to the documentation, there's no need to open the port first:
bq. If the setting is set before opening the port, the actual serial port setting is done automatically in the QSerialPort::open() method right after that the opening of the port succeeds.
This page seem to have changed with time.
Anyway thanks for pointing it out.
franku last edited by
Thanks for the comment. I was working with QExtSerialPort sometime ago and I remember a similar problem before QSerialPort was introduced in a Qt distribution. So maybe I have mixed things up.
You could also try to set the baudrate to i.e. 9600 first and then back to 150kBd again in order to change any underlying variable. But this still wouldn't explain why it works on some PCs and not on others.
On the other hand it may help to debug down to the win32 code of QSerialPort on a system that works and on another that doesn't. Maybe this could help you discover why true ist returned from the software and nothing happens on the hardware.