Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.7.0 Beta3
-
None
Description
The QDialog::exec() function is widely used in existing codebases, particularly with QMessageBox, due to its convenience. However, exec() hampers flexibility by blocking the event loop, which poses a significant challenge when porting applications to WebAssembly. The use of Asyncify is not a universal remedy, as it does not support nested calls.
exec() operates by displaying the dialog and halting further execution until the dialog is dismissed, at which point execution resumes within the same function. Transitioning to the asynchronous open() function as an alternative requires significant code restructuring, often necessitating the division of code across multiple functions, thus adding complexity and requiring extensive tests.
While I am not an expert, I have observed that C++20 introduces coroutines, offering a promising mechanism to suspend execution. This feature potentially enables the development of a compatible exec() function that can pause execution and await user input without necessitating an additional event loop.
Adopting such a solution could significantly ease the process of adapting existing code for compatibility with Qt for WebAssembly, potentially addressing other related challenges as well. Although there are discussions surrounding the use of coroutines, I have yet to find any that specifically address this scenario. However, it is reasonable to expect that the Qt development team, with their deeper understanding, would be better positioned to evaluate this approach.
Implementing this solution could streamline the transition of existing applications to Qt WebAssembly, making it a more feasible endeavor.
Below are some resources I have found helpful:
- Backporting co-routine to c++14
https://ladnir.github.io/blog/2022/01/24/macoro.html - Using coroutins with c++ asio
https://www.youtube.com/watch?v=RBldGKfLb9I - C++20 coroutines + Native webassembly promise integration
https://github.com/emscripten-core/emscripten/issues/20413
Attachments
Issue Links
- relates to
-
QTBUG-102827 [wasm] crash when using Asyncify & exec loops
- Reported
-
QTBUG-103273 Impact of C++20 coroutines on our code
- Open
-
QTBUG-121765 WebAssembly qtloader.js onExit is never called
- In Progress
-
QTBUG-102409 Further Webassembly Enhancements
- Reported