Qt 6.4.0 WebAssembly QToolButton popup menu freezes
-
Hi,
I'm struggling to add a popup menu button to QToolBar.For example in the qt demo:
Examples/Qt-6.4.0/widgets/mainwindows/application/I can add an action with a menu to the toolbar:
// Examples/Qt-6.4.0/widgets/mainwindows/application/mainwindow.cpp ... void MainWindow::createActions() { ... QAction* act = new QAction(newIcon, tr("&fileMenu"), this); act->setMenu (fileMenu); fileToolBar->addAction(act); ... }
In Desktop build, it works as expected. But in Wasm build my browser freezes when I click that icon.
I suspect it is because the sync function Qmenu::exec() instead of Qmenu::popup() is called when QToolButton process the mouse click event. So I followed the suggestion in https://doc-snapshots.qt.io/qt6-dev/wasm.html#asyncify, added -sASYNCIFY to the CMakeLists.txt:
// Examples/Qt-6.4.0/widgets/mainwindows/application/CMakeList.txt ... add_link_options("-sASYNCIFY" "-Os") qt_add_executable(application main.cpp mainwindow.cpp mainwindow.h ) set_target_properties(application PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(application PUBLIC Qt::Core Qt::Gui Qt::Widgets ) ...
However, this doesn't solve the issue. Even worse, now other toolbar icons (Save, Open etc.) will freeze my browser as well, maybe because they have QDialog popup? (It's also mysterious why they can work before I add the -sASYNCIFY flag)
Can someone please help? Any ideas?
Thanks!
-
I also ran into the issue with QToolButton but decided to manually call popup() on the menu instead of using the setMenu() method.
auto filterMenu = new QMenu(ui->filterButton); connect(ui->filterButton, &QToolButton::clicked, filterMenu, [=] { auto pos = ui->filterButton->pos(); filterMenu->popup(QPoint(pos.x(), pos.y() + ui->filterButton->sizeHint().height())); });
That way I could avoid compiling my own Qt with ASYNCIFY support (the ASYNCIFY used to be not supported in older Qt binary releases), so I have not tested that solution. Although moving forward it seems Qt does suggest always using ASYNCIFY https://bugreports.qt.io/browse/QTBUG-94153.