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. When will async/await pattern appear in QT?
Forum Updated to NodeBB v4.3 + New Features

When will async/await pattern appear in QT?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 7.0k Views 2 Watching
  • 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.
  • H Offline
    H Offline
    huskier
    wrote on last edited by huskier
    #1

    I'd like QT's signal/slot mechanism, but I think async/await pattern is more elegant.

    In our application, we've lots of long delayed operations, and after the operations, we need to update the UI. Now we use QThread for the long operations, and then slot functions for the UI updates.

    We've tried boost library's future/then approach; however, we cannot update UI in the "then" part, because the QT is single threaded UI library, and only the main thread could update UI elements.

    If we have async/await pattern in QT, we could simply put the long operations and UI updates together. This will make things simpler.

    So, I wonder QT will support async/await pattern in the future?

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

      Personal opinion:
      no. for 2 reasons:

      1. it would require a huge change in the workings of Qt
      2. (and most important) some OSs (notably Windows afaik) do not support updating UI from anywhere other than the UI thread

      "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

      1 Reply Last reply
      1
      • m.sueM Offline
        m.sueM Offline
        m.sue
        wrote on last edited by
        #3

        Hi,

        Sure, code written in the async-await pattern is easier to read and write. But I would expect Qt to wait until the async-await functionality is part of the C++ standard (or at least a technical specification is approved so that the main compiler builders can implement it ahead of time) before re-inventing the wheel for the n-th time.

        On the other hand, with a long future-then-cascade, where the UI update is the last thing in the line, you can send an update signal to the main thread to refresh the GUI. Also so, with some signals indicating progress in between.

        -Michael.

        1 Reply Last reply
        0
        • H huskier

          I'd like QT's signal/slot mechanism, but I think async/await pattern is more elegant.

          In our application, we've lots of long delayed operations, and after the operations, we need to update the UI. Now we use QThread for the long operations, and then slot functions for the UI updates.

          We've tried boost library's future/then approach; however, we cannot update UI in the "then" part, because the QT is single threaded UI library, and only the main thread could update UI elements.

          If we have async/await pattern in QT, we could simply put the long operations and UI updates together. This will make things simpler.

          So, I wonder QT will support async/await pattern in the future?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @huskier said in When will async/await pattern appear in QT?:

          I think async/await pattern is more elegant.

          I don't. You can use QFuture and QFutureWatcher to get somewhat more refined behavior from the raw QThread approach. Additionally you can implement your own await based on local event loops, but I wouldn't it's just too awkward to read that in C++ and you may run into event-delivery troubles that I (or you) can't foresee.

          QT is single threaded UI library,

          It's because of the window managers. And by the way, ordinarily you'd never need to have threaded UI. Even if the API were thread safe, without the proper serialization you'd just get garbage on the screen.

          I wonder QT will support async/await pattern in the future

          In all probability - no.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • H Offline
            H Offline
            huskier
            wrote on last edited by
            #5

            Thanks for your guys.

            I have my idea now.

            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