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. [Solved] QButtonGroup::checkedId () outputs uncommon result

[Solved] QButtonGroup::checkedId () outputs uncommon result

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 5.0k Views 1 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.
  • JeroentjehomeJ Offline
    JeroentjehomeJ Offline
    Jeroentjehome
    wrote on last edited by
    #2

    Why do you want a groupbox and a buttonGroup? Doesn't just add container in a container?
    The checkedID() should work as in the docs, so are you sure the minus sign isn't an error in your code somewhere? QDebug is nice, but debugging your app with QtCreator is more valuable.

    Greetz, Jeroen

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

      Hi,

      It's the correct behavior. Look at "addButton's documentation":http://qt-project.org/doc/qt-4.8/qbuttongroup.html#addButton it's explained why

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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hareen Laks
        wrote on last edited by
        #4

        @Jeroentje@home,

        Thank you very much for your reply.

        I need to separate those radio buttons from others. Because of that I used the groupbox. And to return the ID of checked radio button I used QButtonGroup.

        It is ok, if any method give me the values of those three buttons as 0, 1, 2 when they checked.

        I checked my code but didn't find any place which cause to -.

        Thanks again.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hareen Laks
          wrote on last edited by
          #5

          @ SGaist,

          Thank you very much for helping me.

          bq. If you are also assigning your own ids, use positive values to avoid conflicts.

          But I couldn't find way to assign my own ids to radio buttons using Designer. :(

          Thanks again..

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

            AFAIK you can't (I might be wrong though but I didn't find anything like that)
            However you can do it by code.

            The question is why do you need these id for and precisely why 0 1 and 2 ?

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

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hareen Laks
              wrote on last edited by
              #7

              SGaist,

              I create a 3 Radio buttons to represent a location of a electrical component.

              There is 3 possible locations Top, Back and Bottom which can be selected by user. According to the selection I have to update the property.

              I have enum like below.

              @ enum COMPONENTLOCATION
              {
              TOP = 0,
              BACK = 1,
              BOTTOM = 2
              };@

              When user change the preferred location I'm going to set that location as below.

              @component->setLocation((ComponentProperties::COMPONENTLOCATION)
              ui->location_button_group->checkedId() );@

              That's why I need 0,1,2..

              Thanking you..

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

                You have three (maybe more) choices then:

                Set the button id programmatically

                Change the enum values

                Use a hash/map to map the button id's to your enum

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

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Hareen Laks
                  wrote on last edited by
                  #9

                  SGaist,

                  I used another method. It is working nicely and with less amount of RadioButtons no problem of coding.

                  I read the text of checked RadioButton.

                  @ui->location_button_group->checkedButton()->text();@

                  Then use if else to setLocation.

                  Thank you very much for your helping hand.

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

                    You're welcome !

                    Since the problem is solved, don't forget to update the tread title so other forum users may know a solution has been found :)

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

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      Hareen Laks
                      wrote on last edited by
                      #11

                      Ok, I'll do it.. :)

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