Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Menu from the action
Qt 6.12 LTS is out! See what's new in the release blog

Menu from the action

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.4k 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by A Former User
    #1

    i'm adding a QMenus to a QWidget, but then when i try to find a menu with the given title, i get nullptr. here's how i'm doing it:

    for(auto action : widget->actions()) {
        QMenu *menu = action->menu();
        if(menu && menu->title() == title)
            return menu;
    }
    return nullptr;
    

    what is wrong?

    jsulmJ 1 Reply Last reply
    0
    • U user4592357

      i'm adding a QMenus to a QWidget, but then when i try to find a menu with the given title, i get nullptr. here's how i'm doing it:

      for(auto action : widget->actions()) {
          QMenu *menu = action->menu();
          if(menu && menu->title() == title)
              return menu;
      }
      return nullptr;
      

      what is wrong?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @user4592357
      What does this output? Is the title you're looking for there?

      for(auto action : widget->actions()) {
          QMenu *menu = action->menu();
          if (menu)
              qDebug() << menu->title();
          if(menu && menu->title() == title)
              return menu;
      }
      return nullptr;
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      U 1 Reply Last reply
      0
      • jsulmJ jsulm

        @user4592357
        What does this output? Is the title you're looking for there?

        for(auto action : widget->actions()) {
            QMenu *menu = action->menu();
            if (menu)
                qDebug() << menu->title();
            if(menu && menu->title() == title)
                return menu;
        }
        return nullptr;
        
        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @jsulm

        i'd tried that. menu is nullptr

        mrjjM 1 Reply Last reply
        0
        • U user4592357

          @jsulm

          i'd tried that. menu is nullptr

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @user4592357
          and what did
          qDebug() << menu->title();

          show/list ?

          U 1 Reply Last reply
          0
          • mrjjM mrjj

            @user4592357
            and what did
            qDebug() << menu->title();

            show/list ?

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @mrjj

            i didn't try that but how could that work if menu was nullptr?

            actually i solved this by getting action's widget and then getting widget's menu and comparing that menu's title to the input title

            jsulmJ 1 Reply Last reply
            0
            • U user4592357

              @mrjj

              i didn't try that but how could that work if menu was nullptr?

              actually i solved this by getting action's widget and then getting widget's menu and comparing that menu's title to the input title

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @user4592357 Maybe it isn't null but the title is different to what you are searching?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              U 1 Reply Last reply
              0
              • jsulmJ jsulm

                @user4592357 Maybe it isn't null but the title is different to what you are searching?

                U Offline
                U Offline
                user4592357
                wrote on last edited by
                #7

                @jsulm

                i figured out what why menu was nullptr. i actually called setMenu() on action's widget, not on actual action, so now i set the menu to the action and the loop works correctly

                1 Reply Last reply
                2

                • Login

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