Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QIODevice transaction mechanism
Forum Updated to NodeBB v4.3 + New Features

QIODevice transaction mechanism

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Corban_Dallas
    wrote on last edited by
    #1

    Hello again!

    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?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      The new fortune client example shows how it works. It uses QDataStream but the idea is exactly the same.

      Shortly:
      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.

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 1 Reply Last reply
      2
      • VRoninV VRonin

        The new fortune client example shows how it works. It uses QDataStream but the idea is exactly the same.

        Shortly:
        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.

        C Offline
        C Offline
        Corban_Dallas
        wrote on last edited by
        #3

        @VRonin I cought it. Great thanks!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved