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. QAction, setting menu breaks / stops triggered signal
Forum Updated to NodeBB v4.3 + New Features

QAction, setting menu breaks / stops triggered signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 234 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    Working on clients system, older version of Qt 4.8.4. Programmatically I'm creating the menu structure:

    void clsMainWnd::addMenu(const QStringList& crslstMenu) {
        if ( crslstMenu.length() < MI_MIN_MENU_OPTIONS ) {
            return;
        }
        if ( mpobjMenuBar == nullptr ) {
            mpobjMenuBar = menuBar();
        }
        QMenu* pobjMenu(nullptr);
        if ( crslstMenu.length() > MI_PARENT_MENU_ID ) {
            tMenusMap::Iterator itFound(mmpMenus
                                              .find(crslstMenu[MI_PARENT_MENU_ID]));
            if ( itFound != mmpMenus.end()
            && (pobjMenu = itFound.value()) != nullptr ) {
                QAction* pobjAction(pobjMenu->addAction(crslstMenu[MI_MENU_TEXT]));
                if ( pobjAction != nullptr ) {
                    pobjAction->setMenu(pobjMenu);
                    pobjAction->setObjectName(QString(crslstMenu[MI_MENU_TEXT]));
                    QObject::connect(pobjMenu, SIGNAL(triggered(QAction*))
                                    ,this, SLOT(onMenuSelected(QAction*)));
                    QObject::connect(pobjAction, SIGNAL(triggered))
                                    ,this, SLOT(onMenuSelected()));
                }
            }
        } else if ( (pobjMenu = new QMenu(crslstMenu[MI_MENU_TEXT]
                                         ,mpobjMenuBar)) != nullptr ) {
            mpobjMenuBar->addMenu(pobjMenu);
            pobjMenu->setObjectName(QString[crslstMenu[MI_MENU_ID]));
            mmpMenus.insert(crslstMenu[MI_MENU_ID], pobjMenu);
        }
    }
    

    The issue is when the line:

    pobjAction->setMenu(pobjMenu);
    

    is included in the code, the triggered signals do not get emitted....why?

    [Edit] I've removed the setMenu as it just doesn't do anything useful except break the code. Instead I've used setProperty and property in the slot to identify the menu action.

    Kind Regards,
    Sy

    Pl45m4P 1 Reply Last reply
    0
    • SPlattenS SPlatten

      Working on clients system, older version of Qt 4.8.4. Programmatically I'm creating the menu structure:

      void clsMainWnd::addMenu(const QStringList& crslstMenu) {
          if ( crslstMenu.length() < MI_MIN_MENU_OPTIONS ) {
              return;
          }
          if ( mpobjMenuBar == nullptr ) {
              mpobjMenuBar = menuBar();
          }
          QMenu* pobjMenu(nullptr);
          if ( crslstMenu.length() > MI_PARENT_MENU_ID ) {
              tMenusMap::Iterator itFound(mmpMenus
                                                .find(crslstMenu[MI_PARENT_MENU_ID]));
              if ( itFound != mmpMenus.end()
              && (pobjMenu = itFound.value()) != nullptr ) {
                  QAction* pobjAction(pobjMenu->addAction(crslstMenu[MI_MENU_TEXT]));
                  if ( pobjAction != nullptr ) {
                      pobjAction->setMenu(pobjMenu);
                      pobjAction->setObjectName(QString(crslstMenu[MI_MENU_TEXT]));
                      QObject::connect(pobjMenu, SIGNAL(triggered(QAction*))
                                      ,this, SLOT(onMenuSelected(QAction*)));
                      QObject::connect(pobjAction, SIGNAL(triggered))
                                      ,this, SLOT(onMenuSelected()));
                  }
              }
          } else if ( (pobjMenu = new QMenu(crslstMenu[MI_MENU_TEXT]
                                           ,mpobjMenuBar)) != nullptr ) {
              mpobjMenuBar->addMenu(pobjMenu);
              pobjMenu->setObjectName(QString[crslstMenu[MI_MENU_ID]));
              mmpMenus.insert(crslstMenu[MI_MENU_ID], pobjMenu);
          }
      }
      

      The issue is when the line:

      pobjAction->setMenu(pobjMenu);
      

      is included in the code, the triggered signals do not get emitted....why?

      [Edit] I've removed the setMenu as it just doesn't do anything useful except break the code. Instead I've used setProperty and property in the slot to identify the menu action.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @SPlatten said in QAction, setting menu breaks / stops triggered signal:

      The issue is when the line:
      pobjAction->setMenu(pobjMenu);

      is included in the code, the triggered signals do not get emitted....why?

      Why?! Expected behavior, I would say...

      If you turn your QAction into a menu (by calling setMenu), you can not "trigger" it anymore, but you open the submenu, when you click it.
      I think, you simply lose the "trigger" functionality by turning your action into a menu action.

      Edit:

      If you want to react on the click anyway, you could try the aboutToShow() signal. This doesn't work for contextMenus since they pop-up on hover and don't need a click, but works in QMenuBars.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved