Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Qt 6.4.0 WebAssembly QToolButton popup menu freezes
QtWS25 Last Chance

Qt 6.4.0 WebAssembly QToolButton popup menu freezes

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
3 Posts 2 Posters 592 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.
  • F Offline
    F Offline
    fyshen13
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Karmo
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fyshen13
        wrote on last edited by
        #3

        Thanks Karmo! Guess I have to do similar thing.

        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