QIODevice transaction mechanism
Transaction mechanism for QIODevice was introduced in Qt5.7. Im still writing the app which working with serial port by async way, so I looked for some examples or tutorials of using it but didnt find. Can someone help and explain to me the right way of using QSerialPort::startTransaction(), QserialPort::commitTransaction() while asynchronously reading data from serial port?
The new fortune client example shows how it works. It uses QDataStream but the idea is exactly the same.
when you write nothing changes, when you read you call
startTransaction()before starting, if you detect an error during the read (for example you did not receive all the data you were expecting yet) then you can call
rollbackTransaction()and the device will not lose all the data you already read but will keep it available for the next read (i.e. it will behave as the first read never occurred). On the other hand, if everything went ok then just call
commitTransaction()to tell the device you are done reading that part.
If you have control on both the sender and the receiver I'd advise using QDataStream as it automatically detects reading errors.
@VRonin I cought it. Great thanks!