I use serial port connection in my qt application. My problem- I cant get back the control (or the values comes from the comm port) after sending the command.
I have
The QSerialPort class inherits from QIODevice which has waitFor...
methods that may be what you're looking for. Take a look at these docs.
If you want to handle the serial port asynchronously, use the readyRead
signal and perform reading in a function that you connected to that signal. If you don't mind that the operation is blocking, the waitForReadyRead
function is what you're looking for.
Here's the proper way to do it using Qt's signals and slots mechanism. This will not block your GUI and lets your application respond to user actions even while you are waiting for the serial port.
bytesWritten
signalreadyRead
signal
The code you want to execute after you read some data from the serial port should be placed in this function.In some cases you can do it like this, but it's blocking, meaning that your GUI will freeze while your app is waiting for the serial port. I don't recommend doing it like this.
waitForBytesWritten
waitForReadyRead
Qt has a vast amount of working example code. There are even examples about how to use QSerialPort, and they are well worth checking out. You might be most interested in the async writer example and the async reader example.