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. QRadioButton signals don't work
Qt 6.12 LTS is out! See what's new in the release blog

QRadioButton signals don't work

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 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.
  • JonBJ JonB

    @Sucharek said in QRadioButton signals don't work:

    QObject::connect(rAuto,SIGNAL(clicked()),SLOT(rAuto_clicked()));

    QObject::connect(rAuto,SIGNAL(clicked()),this,SLOT(rAuto_clicked()));

    Better would be:

    QObject::connect(rAuto, &QRadioButton::clicked, this, &MainWindow::rAuto_clicked);
    

    And of course make sure you actually put that rAuto = new QRadioButton; radiobutton on a widget somewhere!

    S Offline
    S Offline
    Sucharek
    wrote on last edited by
    #3

    Hi @JonB, thanks for your reply, but this doesn't work either.

    I did add the button to MainWindow. It's in a different void.

    JonBJ 1 Reply Last reply
    0
    • S Sucharek

      Hi @JonB, thanks for your reply, but this doesn't work either.

      I did add the button to MainWindow. It's in a different void.

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

      @Sucharek
      The above code should be correct, so I don't know where your problem is or what else you do/do not do.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Hi,

        Nothing in your code hints that you are showing that button.

        Seeing that you have a call to setupUi I would venture that you are clicking on a button you added through Designer and connecting a button you created in code but not shown nor added to said Designer based part.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Nothing in your code hints that you are showing that button.

          Seeing that you have a call to setupUi I would venture that you are clicking on a button you added through Designer and connecting a button you created in code but not shown nor added to said Designer based part.

          S Offline
          S Offline
          Sucharek
          wrote on last edited by
          #6

          Hi @SGaist, I have a different void for adding that button.
          It's like a setup wizard, so I have to change what's in the MainWindow. I have a gridLayout set up in designer, where I add what I need to add or remove.

          I'm adding the button this way:

          ...
          } else if (scene == 4) {
              ...
              ui->gridLayout_Content->addWidget(rAuto, 2, 0);
              ...
          }
          ...
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #7

            Then are you sure that it is really that button that is shown and connected and you did not replace the value in that variable later on ?

            That said, since you mention a wizard, did you consider using QWizard ?

            Also, since it is supposed to be a wizard showing different "scenes", rather than trying to make everything in one single widget, you should rather have one widget per "scene" and use something like QStackedWidget to switch between them.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            0
            • SGaistS SGaist

              Then are you sure that it is really that button that is shown and connected and you did not replace the value in that variable later on ?

              That said, since you mention a wizard, did you consider using QWizard ?

              Also, since it is supposed to be a wizard showing different "scenes", rather than trying to make everything in one single widget, you should rather have one widget per "scene" and use something like QStackedWidget to switch between them.

              S Offline
              S Offline
              Sucharek
              wrote on last edited by
              #8

              @SGaist I'm sure it's the same button.
              I tested it too. I made a button in the editor and when I clicked it, I got if the radio button is toggled. If it was, it printed true, if it wasn't, false. So I'm sure it is that button.

              Thanks for the suggestions. I probably won't use QWizard, because I already have a lot of code written, but I might use QStackedWidget.

              1 Reply Last reply
              0
              • JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by
                #9

                Can you try signal pressed()? You can add different text or background color to this radio button to make sure if it is the right one or not.

                S 1 Reply Last reply
                0
                • JoeCFDJ JoeCFD

                  Can you try signal pressed()? You can add different text or background color to this radio button to make sure if it is the right one or not.

                  S Offline
                  S Offline
                  Sucharek
                  wrote on last edited by
                  #10

                  Hi @JoeCFD, no, that doesn't work too.

                  I know it's the right button. In fact, I have two of them and both are connected to 2 different slots.

                  1 Reply Last reply
                  0
                  • JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by JoeCFD
                    #11

                    @Sucharek said in QRadioButton signals don't work:

                    qDebug()

                    does qDebug() work at other places? Set a break point at

                    qDebug() << "rAuto"; //doesn't print anything
                    
                    S 1 Reply Last reply
                    0
                    • JoeCFDJ JoeCFD

                      @Sucharek said in QRadioButton signals don't work:

                      qDebug()

                      does qDebug() work at other places? Set a break point at

                      qDebug() << "rAuto"; //doesn't print anything
                      
                      S Offline
                      S Offline
                      Sucharek
                      wrote on last edited by
                      #12

                      @JoeCFD yes, qDebug() does work. I tried it on my temporary QPushButton.
                      I think I don't know how to use breakpoints. I set multiple poins, started the app in debug mode, but none of them done anything. Even the ones I know got executed.

                      JoeCFDJ 1 Reply Last reply
                      0
                      • S Sucharek

                        @JoeCFD yes, qDebug() does work. I tried it on my temporary QPushButton.
                        I think I don't know how to use breakpoints. I set multiple poins, started the app in debug mode, but none of them done anything. Even the ones I know got executed.

                        JoeCFDJ Offline
                        JoeCFDJ Offline
                        JoeCFD
                        wrote on last edited by
                        #13

                        @Sucharek replace qDebug() << "rAuto"; with

                        std::cout <<   "========= rAuto"  << std::endl;
                        

                        you need header
                        #include <iostream>

                        It can not be true that the signal of QRadioButton does not work. So many people are using it.

                        S 1 Reply Last reply
                        0
                        • JoeCFDJ JoeCFD

                          @Sucharek replace qDebug() << "rAuto"; with

                          std::cout <<   "========= rAuto"  << std::endl;
                          

                          you need header
                          #include <iostream>

                          It can not be true that the signal of QRadioButton does not work. So many people are using it.

                          S Offline
                          S Offline
                          Sucharek
                          wrote on last edited by
                          #14

                          @JoeCFD, nope, doesn't print anything.
                          I also tried commands likeclose()and they didn't work either.

                          Well, just realised it was my fault all along.
                          Apparently I put therAuto = new QRadioButtonin a wrong place. I put it in a void that sets the buttons text, font size, etc. and I guess I shouldn't do that.

                          Anyways, thanks for the help everyone.

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