Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Please help with actual C++ code
Forum Update on Monday, May 27th 2025

Please help with actual C++ code

Scheduled Pinned Locked Moved Unsolved C++ Gurus
25 Posts 5 Posters 3.5k 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on 20 Jan 2024, 15:48 last edited by
    #1

    I am, honestly trying hard to learn C++, but RTFM does not help i n this case.

    The first line of code complies ans adds new sub menu with text.
    Not really understand how , but that is irrelevant.

    The second line won't compile and I get ton of error messages, none of them suggest the correct syntax to add check box to the menu.

    I really tried to read the errors to find the correct syntax, but no luck.
    So I am asking for correction to my code.

    Maybe later I will post the errors and let somebody explain to me how to read them to find correct syntax.

        QAction tempAction;
                        subMenu[index]->addAction(" test ");
                        subMenu[index]->addAction(tempAction.setCheckable(true));
    

    Here are is my current , basic error messages

    /mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth.cpp:3590: error: no matching member function for call to 'addAction'
    mainwindow_Bluetooth.cpp:3590:37: error: no matching member function for call to 'addAction'
                        subMenu[index]->addAction(tempAction.setCheckable(true));
                        ~~~~~~~~~~~~~~~~^~~~~~~~~
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qwidget.h:559:10: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'QAction *' for 1st argument
        void addAction(QAction *action);
             ^
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:79:14: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'const QString' for 1st argument
        QAction *addAction(const QString &text);
                 ^
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:80:14: note: candidate function not viable: requires 2 arguments, but 1 was provided
        QAction *addAction(const QIcon &icon, const QString &text);
                 ^
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:111:21: note: candidate function template not viable: requires at least 2 arguments, but 1 was provided
        inline QAction *addAction(const QString &text, Func1 slot, const QKeySequence &shortcut = 0)
                        ^
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:81:14: note: candidate function not viable: requires at least 3 arguments, but 1 was provided
        QAction *addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
                 ^
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:98:9: note: candidate function template not viable: requires at least 3 arguments, but 1 was provided
            addAction(const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0)
            ^
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:139:21: note: candidate function template not viable: requires at least 3 arguments, but 1 was provided
        inline QAction *addAction(const QIcon &actionIcon, const QString &text, Func1 slot, const QKeySequence &shortcut = 0)
                        ^
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:82:14: note: candidate function not viable: requires at least 4 arguments, but 1 was provided
        QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
                 ^
    /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:126:9: note: candidate function template not viable: requires at least 4 arguments, but 1 was provided
            addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0)
            ^
    
    J A 2 Replies Last reply 20 Jan 2024, 16:13
    0
    • A Anonymous_Banned275
      20 Jan 2024, 15:48

      I am, honestly trying hard to learn C++, but RTFM does not help i n this case.

      The first line of code complies ans adds new sub menu with text.
      Not really understand how , but that is irrelevant.

      The second line won't compile and I get ton of error messages, none of them suggest the correct syntax to add check box to the menu.

      I really tried to read the errors to find the correct syntax, but no luck.
      So I am asking for correction to my code.

      Maybe later I will post the errors and let somebody explain to me how to read them to find correct syntax.

          QAction tempAction;
                          subMenu[index]->addAction(" test ");
                          subMenu[index]->addAction(tempAction.setCheckable(true));
      

      Here are is my current , basic error messages

      /mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth.cpp:3590: error: no matching member function for call to 'addAction'
      mainwindow_Bluetooth.cpp:3590:37: error: no matching member function for call to 'addAction'
                          subMenu[index]->addAction(tempAction.setCheckable(true));
                          ~~~~~~~~~~~~~~~~^~~~~~~~~
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qwidget.h:559:10: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'QAction *' for 1st argument
          void addAction(QAction *action);
               ^
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:79:14: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'const QString' for 1st argument
          QAction *addAction(const QString &text);
                   ^
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:80:14: note: candidate function not viable: requires 2 arguments, but 1 was provided
          QAction *addAction(const QIcon &icon, const QString &text);
                   ^
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:111:21: note: candidate function template not viable: requires at least 2 arguments, but 1 was provided
          inline QAction *addAction(const QString &text, Func1 slot, const QKeySequence &shortcut = 0)
                          ^
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:81:14: note: candidate function not viable: requires at least 3 arguments, but 1 was provided
          QAction *addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
                   ^
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:98:9: note: candidate function template not viable: requires at least 3 arguments, but 1 was provided
              addAction(const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0)
              ^
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:139:21: note: candidate function template not viable: requires at least 3 arguments, but 1 was provided
          inline QAction *addAction(const QIcon &actionIcon, const QString &text, Func1 slot, const QKeySequence &shortcut = 0)
                          ^
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:82:14: note: candidate function not viable: requires at least 4 arguments, but 1 was provided
          QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
                   ^
      /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:126:9: note: candidate function template not viable: requires at least 4 arguments, but 1 was provided
              addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0)
              ^
      
      J Offline
      J Offline
      JonB
      wrote on 20 Jan 2024, 16:13 last edited by JonB
      #2

      @AnneRanch
      As per the first line, addAction(" test "), you can call addAction() with a string. Or you can call it with a QAction * you have created. But tempAction.setCheckable(true) class a method which returns void, there is no chance of passing this to anything as a parameter.

      There are a couple of ways of doing what you want. What about this:

      QAction *tempAction = subMenu[index]->addAction(" test ");
      tempAction->setCheckable(true);
      
      // or equivalent, does not matter which one you do, above is one line less code
      QAction* tempAction = new QAction(" test ", this);
      tempAction->setCheckable(true);
      subMenu[index]->addAction(tempAction);
      
      A 1 Reply Last reply 20 Jan 2024, 17:23
      1
      • A Anonymous_Banned275
        20 Jan 2024, 15:48

        I am, honestly trying hard to learn C++, but RTFM does not help i n this case.

        The first line of code complies ans adds new sub menu with text.
        Not really understand how , but that is irrelevant.

        The second line won't compile and I get ton of error messages, none of them suggest the correct syntax to add check box to the menu.

        I really tried to read the errors to find the correct syntax, but no luck.
        So I am asking for correction to my code.

        Maybe later I will post the errors and let somebody explain to me how to read them to find correct syntax.

            QAction tempAction;
                            subMenu[index]->addAction(" test ");
                            subMenu[index]->addAction(tempAction.setCheckable(true));
        

        Here are is my current , basic error messages

        /mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11/A_BT_LIBRARY/terminal_Bluetooth/mainwindow_Bluetooth.cpp:3590: error: no matching member function for call to 'addAction'
        mainwindow_Bluetooth.cpp:3590:37: error: no matching member function for call to 'addAction'
                            subMenu[index]->addAction(tempAction.setCheckable(true));
                            ~~~~~~~~~~~~~~~~^~~~~~~~~
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qwidget.h:559:10: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'QAction *' for 1st argument
            void addAction(QAction *action);
                 ^
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:79:14: note: candidate function not viable: cannot convert argument of incomplete type 'void' to 'const QString' for 1st argument
            QAction *addAction(const QString &text);
                     ^
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:80:14: note: candidate function not viable: requires 2 arguments, but 1 was provided
            QAction *addAction(const QIcon &icon, const QString &text);
                     ^
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:111:21: note: candidate function template not viable: requires at least 2 arguments, but 1 was provided
            inline QAction *addAction(const QString &text, Func1 slot, const QKeySequence &shortcut = 0)
                            ^
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:81:14: note: candidate function not viable: requires at least 3 arguments, but 1 was provided
            QAction *addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
                     ^
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:98:9: note: candidate function template not viable: requires at least 3 arguments, but 1 was provided
                addAction(const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0)
                ^
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:139:21: note: candidate function template not viable: requires at least 3 arguments, but 1 was provided
            inline QAction *addAction(const QIcon &actionIcon, const QString &text, Func1 slot, const QKeySequence &shortcut = 0)
                            ^
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:82:14: note: candidate function not viable: requires at least 4 arguments, but 1 was provided
            QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
                     ^
        /home/nov25-1/Qt/5.15.2/gcc_64/include/QtWidgets/qmenu.h:126:9: note: candidate function template not viable: requires at least 4 arguments, but 1 was provided
                addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0)
                ^
        
        A Offline
        A Offline
        Axel Spoerl
        Moderators
        wrote on 20 Jan 2024, 16:25 last edited by
        #3

        The error messages list all overrides of QWidget::addAction(), none of which matches the 2nd call to this method. That's where reading the documentation really helps. I disagree with you. RTM is exactly what could have prevented your issue. Drop the F. Bad karma.

        The difficulty is now, that one the one hand you want to learn C++ without reading much, on the other hand you don't tell us, what you actually want to do. Add one action and make it checkable? Add two actions? What is the heap allocated tempActionsupposed to be? It'll go out of scope when the function returns - that's a risky ride.

        Since you (as usual) won't answer any of those questions, here is some C++ code that is as similar to yours as possible. It will compile, and it won't cause crashes. Maybe it even does what you expect. We will never know, because usually you won't tell.

        QAction *tempAction = subMenu[index]->addAction(" test ");
        tempAction->setCheckable(true));
        

        Software Engineer
        The Qt Company, Oslo

        A 1 Reply Last reply 20 Jan 2024, 16:30
        0
        • A Axel Spoerl
          20 Jan 2024, 16:25

          The error messages list all overrides of QWidget::addAction(), none of which matches the 2nd call to this method. That's where reading the documentation really helps. I disagree with you. RTM is exactly what could have prevented your issue. Drop the F. Bad karma.

          The difficulty is now, that one the one hand you want to learn C++ without reading much, on the other hand you don't tell us, what you actually want to do. Add one action and make it checkable? Add two actions? What is the heap allocated tempActionsupposed to be? It'll go out of scope when the function returns - that's a risky ride.

          Since you (as usual) won't answer any of those questions, here is some C++ code that is as similar to yours as possible. It will compile, and it won't cause crashes. Maybe it even does what you expect. We will never know, because usually you won't tell.

          QAction *tempAction = subMenu[index]->addAction(" test ");
          tempAction->setCheckable(true));
          
          A Offline
          A Offline
          Axel Spoerl
          Moderators
          wrote on 20 Jan 2024, 16:30 last edited by
          #4

          @JonB
          Simple minds think alike. @JonB was not only faster, but also a much better explainer.

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          0
          • J JonB
            20 Jan 2024, 16:13

            @AnneRanch
            As per the first line, addAction(" test "), you can call addAction() with a string. Or you can call it with a QAction * you have created. But tempAction.setCheckable(true) class a method which returns void, there is no chance of passing this to anything as a parameter.

            There are a couple of ways of doing what you want. What about this:

            QAction *tempAction = subMenu[index]->addAction(" test ");
            tempAction->setCheckable(true);
            
            // or equivalent, does not matter which one you do, above is one line less code
            QAction* tempAction = new QAction(" test ", this);
            tempAction->setCheckable(true);
            subMenu[index]->addAction(tempAction);
            
            A Offline
            A Offline
            Anonymous_Banned275
            wrote on 20 Jan 2024, 17:23 last edited by
            #5

            @JonB OK, here is my take on this.
            I understand that I am using QMenu method "addAction".
            "addAction" takes parameters as any function/ method.
            When I pass text the result is - new menu of text gets created. . That is probably explained in doc, but it is weird how text creates new menu.But that is OK and I am using that and it does the job.

            Now I want to use QAction method "addCheckable" as a parameter to "addAction". That has no relation to "text"....

            So I need to create QAction object.
            Am I correct so far ?

            Chris KawaC 1 Reply Last reply 20 Jan 2024, 18:13
            0
            • A Anonymous_Banned275
              20 Jan 2024, 17:23

              @JonB OK, here is my take on this.
              I understand that I am using QMenu method "addAction".
              "addAction" takes parameters as any function/ method.
              When I pass text the result is - new menu of text gets created. . That is probably explained in doc, but it is weird how text creates new menu.But that is OK and I am using that and it does the job.

              Now I want to use QAction method "addCheckable" as a parameter to "addAction". That has no relation to "text"....

              So I need to create QAction object.
              Am I correct so far ?

              Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on 20 Jan 2024, 18:13 last edited by
              #6

              Menus are containers. Actions are elements in that container.

              menu->addAction("hello") creates an action with text "hello" and adds it to a menu.
              menu->addMenu("hello") creates a new menu, then creates an action that opens this menu with text "hello" and adds that action to the original menu.
              menu->menuAction() returns an action that opens this menu.

              Maybe this example helps:

              menus example

              QMenu* menu = menuBar->addMenu("Action that opens menu");
              QAction* actionThatOpensMenu = menu->menuAction();
              
              QAction* actionInMenu = menu->addAction("Action in menu");
              
              QAction* checkableActionInMenu = menu->addAction("Checkable action in menu");
              checkableActionInMenu->setCheckable(true);
              
              QMenu* subMenu = menu->addMenu("Action that opens sub menu");
              QAction* actionThatOpensSubMenu = subMenu->menuAction();
              
              QAction* actionInSubMenu = subMenu->addAction("Action in sub menu");
              
              QAction* checkableActionInSubMenu = subMenu->addAction("Checkable action in sub menu");
              checkableActionInSubMenu->setCheckable(true);
              
              A 1 Reply Last reply 20 Jan 2024, 18:27
              2
              • Chris KawaC Chris Kawa
                20 Jan 2024, 18:13

                Menus are containers. Actions are elements in that container.

                menu->addAction("hello") creates an action with text "hello" and adds it to a menu.
                menu->addMenu("hello") creates a new menu, then creates an action that opens this menu with text "hello" and adds that action to the original menu.
                menu->menuAction() returns an action that opens this menu.

                Maybe this example helps:

                menus example

                QMenu* menu = menuBar->addMenu("Action that opens menu");
                QAction* actionThatOpensMenu = menu->menuAction();
                
                QAction* actionInMenu = menu->addAction("Action in menu");
                
                QAction* checkableActionInMenu = menu->addAction("Checkable action in menu");
                checkableActionInMenu->setCheckable(true);
                
                QMenu* subMenu = menu->addMenu("Action that opens sub menu");
                QAction* actionThatOpensSubMenu = subMenu->menuAction();
                
                QAction* actionInSubMenu = subMenu->addAction("Action in sub menu");
                
                QAction* checkableActionInSubMenu = subMenu->addAction("Checkable action in sub menu");
                checkableActionInSubMenu->setCheckable(true);
                
                A Offline
                A Offline
                Anonymous_Banned275
                wrote on 20 Jan 2024, 18:27 last edited by
                #7

                @Chris-Kawa Thanks Chris - I am willing to redo my clumsy code...

                Give me some time to digest your post.
                Yes it has been a struggle to keep QMenu and QAction working with each other.

                I did implement last suggestion with mixed result - I get "check box" as a last entry in submenu without any text .

                I am posting my current messy code FOR ENTERTAINMENT purpose ONLY.

                Let me take a detailed look at the code you posted BEFORE any more suggestions , OK ?

                                  QAction* tempAction = new QAction(); //  text , this);
                                    tempAction->setCheckable(true);
                                    //subMenu[index]->addAction(tempAction);
                                    for (index_sub = 0; index_sub < subSize; ++index_sub)
                                    { // inner loop
                                        { // process block
                                            { // add subsub menu
                                                text = " index_sub " ;
                                                text += QString::number(index_sub);
                                                qDebug()<<text;
                
                
                                                subMenu[index]->addAction(list_array[index][ index_sub] + " #" + QString::number( index_sub));
                
                                                //tempAction->setCheckable(true);
                                                subMenu[index]->addAction(tempAction);
                
                
                
                

                .

                A 1 Reply Last reply 20 Jan 2024, 19:25
                0
                • A Anonymous_Banned275
                  20 Jan 2024, 18:27

                  @Chris-Kawa Thanks Chris - I am willing to redo my clumsy code...

                  Give me some time to digest your post.
                  Yes it has been a struggle to keep QMenu and QAction working with each other.

                  I did implement last suggestion with mixed result - I get "check box" as a last entry in submenu without any text .

                  I am posting my current messy code FOR ENTERTAINMENT purpose ONLY.

                  Let me take a detailed look at the code you posted BEFORE any more suggestions , OK ?

                                    QAction* tempAction = new QAction(); //  text , this);
                                      tempAction->setCheckable(true);
                                      //subMenu[index]->addAction(tempAction);
                                      for (index_sub = 0; index_sub < subSize; ++index_sub)
                                      { // inner loop
                                          { // process block
                                              { // add subsub menu
                                                  text = " index_sub " ;
                                                  text += QString::number(index_sub);
                                                  qDebug()<<text;
                  
                  
                                                  subMenu[index]->addAction(list_array[index][ index_sub] + " #" + QString::number( index_sub));
                  
                                                  //tempAction->setCheckable(true);
                                                  subMenu[index]->addAction(tempAction);
                  
                  
                  
                  

                  .

                  A Offline
                  A Offline
                  Anonymous_Banned275
                  wrote on 20 Jan 2024, 19:25 last edited by
                  #8

                  @AnneRanch OK, I changed bunch of code and got Chris suggestion working as expected . It adds single entry to main menus , so I need to work on that.

                  Thanks Chris.

                  A 1 Reply Last reply 20 Jan 2024, 21:13
                  0
                  • A Anonymous_Banned275
                    20 Jan 2024, 19:25

                    @AnneRanch OK, I changed bunch of code and got Chris suggestion working as expected . It adds single entry to main menus , so I need to work on that.

                    Thanks Chris.

                    A Offline
                    A Offline
                    Anonymous_Banned275
                    wrote on 20 Jan 2024, 21:13 last edited by
                    #9

                    @AnneRanch

                    Here is my current , working , main loop code...

                                   { // // main menu process block
                    #ifdef ARRAY
                                        text = " main menu process block ";
                                        qDebug() << text;
                    #endif
                                        // start with action
                                        // attach to existing menu
                                        new_mainAction[index] = m_ui->menuWindow_cpntrol->menuAction(); // C
                                        new_checkableActionInMenu[index] = m_ui->menuWindow_cpntrol->addAction(list[index] + " # " + QString::number(index));
                                        
                                        
                                        new_checkableActionInMenu[index]->setCheckable(true);        // TOK
                                        //checkableActionInMenu[index]->setCheckable(false);       // TOK
                                        
                                    } // main menu process block
                    

                    I cannot help to say - there is a real difference in contributing to solution with few lines of REAL issue description and ....

                    Unfortunately...

                    Thanks a million Chris I owe you a beer.
                    Real Czech Pilsner or ??

                    A 1 Reply Last reply 21 Jan 2024, 02:54
                    0
                    • A Anonymous_Banned275
                      20 Jan 2024, 21:13

                      @AnneRanch

                      Here is my current , working , main loop code...

                                     { // // main menu process block
                      #ifdef ARRAY
                                          text = " main menu process block ";
                                          qDebug() << text;
                      #endif
                                          // start with action
                                          // attach to existing menu
                                          new_mainAction[index] = m_ui->menuWindow_cpntrol->menuAction(); // C
                                          new_checkableActionInMenu[index] = m_ui->menuWindow_cpntrol->addAction(list[index] + " # " + QString::number(index));
                                          
                                          
                                          new_checkableActionInMenu[index]->setCheckable(true);        // TOK
                                          //checkableActionInMenu[index]->setCheckable(false);       // TOK
                                          
                                      } // main menu process block
                      

                      I cannot help to say - there is a real difference in contributing to solution with few lines of REAL issue description and ....

                      Unfortunately...

                      Thanks a million Chris I owe you a beer.
                      Real Czech Pilsner or ??

                      A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on 21 Jan 2024, 02:54 last edited by Anonymous_Banned275
                      #10

                      @AnneRanch

                      I am stuck again
                      here is the working snippet

                                     // attach to existing menu
                                      subMenu_mainAction[index] = m_ui->menuWindow_cpntrol->menuAction(); // C
                                      subMenu_checkableActionInMenu[index] = m_ui->menuWindow_cpntrol->addAction(list[index] + " # " + QString::number(index));
                                      subMenu_checkableActionInMenu[index]->setCheckable(true);
                      
                                      // here need  subMenu  **menu** ?? 
                      

                      If I understand the workings of adding subMenu ,

                      I start with the existing "widget " - QMenu .

                      subMenu_mainAction[index] = m_ui->menuWindow_cpntrol->menuAction();

                      To add subsubMenu - don't I need the added subMenu menu?

                      All i have are "actions" and no real subMenu.

                      Chris KawaC 1 Reply Last reply 21 Jan 2024, 08:22
                      0
                      • A Anonymous_Banned275
                        21 Jan 2024, 02:54

                        @AnneRanch

                        I am stuck again
                        here is the working snippet

                                       // attach to existing menu
                                        subMenu_mainAction[index] = m_ui->menuWindow_cpntrol->menuAction(); // C
                                        subMenu_checkableActionInMenu[index] = m_ui->menuWindow_cpntrol->addAction(list[index] + " # " + QString::number(index));
                                        subMenu_checkableActionInMenu[index]->setCheckable(true);
                        
                                        // here need  subMenu  **menu** ?? 
                        

                        If I understand the workings of adding subMenu ,

                        I start with the existing "widget " - QMenu .

                        subMenu_mainAction[index] = m_ui->menuWindow_cpntrol->menuAction();

                        To add subsubMenu - don't I need the added subMenu menu?

                        All i have are "actions" and no real subMenu.

                        Chris KawaC Offline
                        Chris KawaC Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on 21 Jan 2024, 08:22 last edited by
                        #11
                        QMenu* menu = menuBar->AddMenu("menu");
                        QMenu* subMenu = menu->AddMenu("sub menu");
                        QMenu* subSubMenu = subMenu->AddMenu("sub sub menu");
                        QMenu* subSubSubMenu = subSubMenu->AddMenu("sub sub sub menu");
                        QMenu* subSubSubSubMenu = subSubSubMenu->AddMenu("sub sub sub sub menu");
                        ...
                        

                        Menus all the way down :)

                        A 1 Reply Last reply 21 Jan 2024, 15:14
                        0
                        • Chris KawaC Chris Kawa
                          21 Jan 2024, 08:22
                          QMenu* menu = menuBar->AddMenu("menu");
                          QMenu* subMenu = menu->AddMenu("sub menu");
                          QMenu* subSubMenu = subMenu->AddMenu("sub sub menu");
                          QMenu* subSubSubMenu = subSubMenu->AddMenu("sub sub sub menu");
                          QMenu* subSubSubSubMenu = subSubSubMenu->AddMenu("sub sub sub sub menu");
                          ...
                          

                          Menus all the way down :)

                          A Offline
                          A Offline
                          Anonymous_Banned275
                          wrote on 21 Jan 2024, 15:14 last edited by
                          #12
                          This post is deleted!
                          A 1 Reply Last reply 21 Jan 2024, 18:36
                          0
                          • A Anonymous_Banned275
                            21 Jan 2024, 15:14

                            This post is deleted!

                            A Offline
                            A Offline
                            Anonymous_Banned275
                            wrote on 21 Jan 2024, 18:36 last edited by
                            #13
                            This post is deleted!
                            Chris KawaC 1 Reply Last reply 21 Jan 2024, 18:46
                            0
                            • A Anonymous_Banned275
                              21 Jan 2024, 18:36

                              This post is deleted!

                              Chris KawaC Offline
                              Chris KawaC Offline
                              Chris Kawa
                              Lifetime Qt Champion
                              wrote on 21 Jan 2024, 18:46 last edited by
                              #14

                              I would try to help, but I've no idea what you're trying to achieve. Code you posted makes no sense unfortunately.

                              Maybe you could draw a layout you want and I can help achieve it in code?

                              A 1 Reply Last reply 21 Jan 2024, 18:54
                              1
                              • Chris KawaC Chris Kawa
                                21 Jan 2024, 18:46

                                I would try to help, but I've no idea what you're trying to achieve. Code you posted makes no sense unfortunately.

                                Maybe you could draw a layout you want and I can help achieve it in code?

                                A Offline
                                A Offline
                                Anonymous_Banned275
                                wrote on 21 Jan 2024, 18:54 last edited by
                                #15
                                This post is deleted!
                                J 1 Reply Last reply 21 Jan 2024, 18:59
                                0
                                • A Anonymous_Banned275
                                  21 Jan 2024, 18:54

                                  This post is deleted!

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 21 Jan 2024, 18:59 last edited by JonB
                                  #16

                                  @AnneRanch said in Please help with actual C++ code:

                                  I have been told I cannot have "check box : in main menu

                                  You can have a checkbox on an action in any menu, "main" or not. These are created via QMenu::addAction().

                                  However, if you instead add an item which is a submenu (a > that you click on to display a "slide-out" menu) you cannot have a checkbox on that item. These are created via QMenu::addMenu(). And if you think about it, what would be the point of having a checkbox on a menu item which just displays a submenu anyway?

                                  A 1 Reply Last reply 21 Jan 2024, 19:16
                                  1
                                  • J JonB
                                    21 Jan 2024, 18:59

                                    @AnneRanch said in Please help with actual C++ code:

                                    I have been told I cannot have "check box : in main menu

                                    You can have a checkbox on an action in any menu, "main" or not. These are created via QMenu::addAction().

                                    However, if you instead add an item which is a submenu (a > that you click on to display a "slide-out" menu) you cannot have a checkbox on that item. These are created via QMenu::addMenu(). And if you think about it, what would be the point of having a checkbox on a menu item which just displays a submenu anyway?

                                    A Offline
                                    A Offline
                                    Anonymous_Banned275
                                    wrote on 21 Jan 2024, 19:16 last edited by
                                    #17
                                    This post is deleted!
                                    A 1 Reply Last reply 21 Jan 2024, 23:16
                                    0
                                    • A Anonymous_Banned275
                                      21 Jan 2024, 19:16

                                      This post is deleted!

                                      A Offline
                                      A Offline
                                      Anonymous_Banned275
                                      wrote on 21 Jan 2024, 23:16 last edited by
                                      #18
                                      This post is deleted!
                                      1 Reply Last reply
                                      0
                                      • TomZT Offline
                                        TomZT Offline
                                        TomZ
                                        wrote on 22 Jan 2024, 13:23 last edited by
                                        #19

                                        reading this generally,

                                        @AnneRanch said in Please help with actual C++ code:

                                        The widow just do part of the interface and then I will oopen anither widow to continue... eventually all windows will comlete the required task. So when it is all done I can close it and it would be nice to reopen ALL of then at once when required...hence I thought it could be done in main window...
                                        The whole idea to have uncluttered interaction as required -- one window At the time...

                                        I have the strong suspicion you're trying to implement a GUI idea using existing components which are not actually meant to be used like that at all.
                                        Specifically, QMenu and its related classes are NOT supposed to be used like windows. You're not going to get a good user experience using this kind of windows.

                                        If you share your GUI idea you might get suggestions on how to approach the app.

                                        I suspect a QML component will give you a LOT more flexibility that will allow you to get a good user experience.

                                        A 1 Reply Last reply 22 Jan 2024, 13:51
                                        1
                                        • TomZT TomZ
                                          22 Jan 2024, 13:23

                                          reading this generally,

                                          @AnneRanch said in Please help with actual C++ code:

                                          The widow just do part of the interface and then I will oopen anither widow to continue... eventually all windows will comlete the required task. So when it is all done I can close it and it would be nice to reopen ALL of then at once when required...hence I thought it could be done in main window...
                                          The whole idea to have uncluttered interaction as required -- one window At the time...

                                          I have the strong suspicion you're trying to implement a GUI idea using existing components which are not actually meant to be used like that at all.
                                          Specifically, QMenu and its related classes are NOT supposed to be used like windows. You're not going to get a good user experience using this kind of windows.

                                          If you share your GUI idea you might get suggestions on how to approach the app.

                                          I suspect a QML component will give you a LOT more flexibility that will allow you to get a good user experience.

                                          A Offline
                                          A Offline
                                          Anonymous_Banned275
                                          wrote on 22 Jan 2024, 13:51 last edited by
                                          #20

                                          @TomZ Thanks, however... I am just extending "windows
                                          ...tile...cascade..." menu using mdiArea (example). I have it essentially working, include "connect". The "problem is " - it can be started with QMenu -that makes submenu extension easy - but adding "checkable " to sub menu is currently failing. Or I can start with QAction then adding depended sub menu fails. Right now I feel starting with "cascading menus " is cleaner ..in case I want to add sususbsub....
                                          The "user" -me - has several depended tasks to accomplish - setup serial connection, then setup dependent Bluetooth connection, configure remote Bluetooth device and then attach it to "serial connection" etc.,key remote device - amateur radio transmitter, listen to "meteor scatter" pings on Internet ...
                                          The basic idea is to do all this in separate forms , I got that going, to keep monitor and me , focused on task...

                                          A 1 Reply Last reply 22 Jan 2024, 15:58
                                          0

                                          1/25

                                          20 Jan 2024, 15:48

                                          • Login

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