Unsolved When will async/await pattern appear in QT?
-
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?
-
Personal opinion:
no. for 2 reasons:- it would require a huge change in the workings of Qt
- (and most important) some OSs (notably Windows afaik) do not support updating UI from anywhere other than the UI thread
-
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.
-
@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.
-
Thanks for your guys.
I have my idea now.