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. Problem connecting QAction to slot
Forum Updated to NodeBB v4.3 + New Features

Problem connecting QAction to slot

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.6k 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.
  • J Jakob Clausen

    Hi. I am trying to use a QToolBar to navigate through a QStackedWidget, but I cannot seem to connect the signals.
    I have

    QAction* ToolBar::addNavigationButton(QString name, QStackedWidget* workspace, int index)
    {
        QAction* action = new QAction(this);
        action->setObjectName(name);
        action->setCheckable(true);
        actionGroup.addAction(action);
        connect(action, &QAction::triggered, this, [=]() {workspace->setCurrentIndex(index);});
        return action;
    }
    

    And at the connect-line QtCreator says: QAction::triggered is not a signal (clazy-connect-non-signal).
    What am I missing. is QAction::triggered not a signal?

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #2

    @Jakob-Clausen
    This is not an error from the compiler, it's from clazy. And it's wrong, you have correct signal, it compiles. So ignore clazy!

    1 Reply Last reply
    3
    • J Offline
      J Offline
      Jakob Clausen
      wrote on last edited by
      #3

      Nothing happens when I push the button.

      JonBJ 2 Replies Last reply
      0
      • J Jakob Clausen

        Nothing happens when I push the button.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #4

        @Jakob-Clausen
        Put a qDebug() into the slot lambda?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jakob Clausen
          wrote on last edited by
          #5

          No. Nothing happens.

          1 Reply Last reply
          0
          • J Jakob Clausen

            Nothing happens when I push the button.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #6

            @Jakob-Clausen
            I have not used a checkable QAction. But I'm thinking it does not fire triggered(), it fires changed() instead? Because it no longer triggers an "action"? Check the docs/comment out the setCheckable(true).

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jakob Clausen
              wrote on last edited by
              #7

              If I comment out setCheckable() it gives the same result.
              I have also tried to connect changed(), and it does not work either.

              If I use a pushbutton instread, then I can make it work

                  Button* button = new Button(this, name);
                  button->setCheckable(true);
                  connect(button, &Button::pressed, this, [=]() {workspace->setCurrentIndex(index);});
                  return addWidget(button);
              

              Is this a bad way to do it?
              I guess I manually have to uncheck the previous button that was checked.

              jsulmJ 1 Reply Last reply
              0
              • J Jakob Clausen

                If I comment out setCheckable() it gives the same result.
                I have also tried to connect changed(), and it does not work either.

                If I use a pushbutton instread, then I can make it work

                    Button* button = new Button(this, name);
                    button->setCheckable(true);
                    connect(button, &Button::pressed, this, [=]() {workspace->setCurrentIndex(index);});
                    return addWidget(button);
                

                Is this a bad way to do it?
                I guess I manually have to uncheck the previous button that was checked.

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @Jakob-Clausen Isn't https://doc.qt.io/qt-5/qaction.html#toggled what you're looking for?

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

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jakob Clausen
                  wrote on last edited by
                  #9

                  Same result.

                  JonBJ KroMignonK 2 Replies Last reply
                  0
                  • J Jakob Clausen

                    Same result.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #10

                    @Jakob-Clausen
                    Since it ought to work, and we are about to give up :), can you test it without that QActionGroup, just in case...? Else test it in a tiny, standalone.

                    1 Reply Last reply
                    0
                    • J Jakob Clausen

                      Same result.

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by KroMignon
                      #11

                      @Jakob-Clausen said in Problem connecting QAction to slot:

                      Same result.

                      Maybe a silly question, but did you add the action to a widget?
                      Extract from QAction documentation:

                      Note that an action must be added to a widget before it can be used; this is also true when the shortcut should be global (i.e., Qt::ApplicationShortcut as Qt::ShortcutContext).

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      J 1 Reply Last reply
                      1
                      • KroMignonK KroMignon

                        @Jakob-Clausen said in Problem connecting QAction to slot:

                        Same result.

                        Maybe a silly question, but did you add the action to a widget?
                        Extract from QAction documentation:

                        Note that an action must be added to a widget before it can be used; this is also true when the shortcut should be global (i.e., Qt::ApplicationShortcut as Qt::ShortcutContext).

                        J Offline
                        J Offline
                        Jakob Clausen
                        wrote on last edited by
                        #12

                        @KroMignon Maybe so. But that was it. If I add it, then it works. Clazy still complains, and I don't know what that means. But now its working. :-)
                        Thank you very much.

                        KroMignonK 1 Reply Last reply
                        0
                        • J Jakob Clausen

                          @KroMignon Maybe so. But that was it. If I add it, then it works. Clazy still complains, and I don't know what that means. But now its working. :-)
                          Thank you very much.

                          KroMignonK Offline
                          KroMignonK Offline
                          KroMignon
                          wrote on last edited by KroMignon
                          #13

                          @Jakob-Clausen said in Problem connecting QAction to slot:

                          Clazy still complains

                          The Clazy complain seems to be a bug in Clazy/QtCreator ==> https://bugreports.qt.io/browse/QTCREATORBUG-25165

                          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                          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 Extensions
                          • Unsolved