[SOLVED] How to get selected radio button value?



  • Hi, I have a form with many radio buttons like this

    http://tinypic.com/view.php?pic=mkeyqt&s=8#.U6FVbPmSwms

    I want to get the value of radio button for each line so I tried out the easy way of printing the value of the selected radio button for let's say Interconnect Enabled.

    @
    QString ru_interconnect;

    if (ui->radioButton_22->isChecked()) //selection is Yes
    {

        ru_interconnect = "Y";
        qDebug() << "Interconnect Yes is checked" << ru_interconnect;
    } else if (ui->radioButton_23->isChecked()) // selection is No
    {
    
        ru_interconnect = "N";
         qDebug() << "Interconnect No is checked" << ru_interconnect;
    }
    

    @

    I link it to a push button so that upon clicking the button, the value will be displayed. No results was shown in the compilation box. The Yes/No buttons on each line are grouped.
    I did the same for lineedit and the values can be printed. Any idea on how to solve this?



  • Hi,
    A bit more code needed. How did you link the 'ru_interconnect' to a pushbutton? Do you use signal/slots?



  • From the push button. I just go to slot via clicked event. I code this in the clicked function.



  • Yes, so, the push button emits a clicked signal, you did connect it to a slot to print the text? What does your debugger do? Does it reach the pushbutton clicked slot? In your output pane you could see if the connection had errors and the signal/slot is not setup properly.
    And when you click the puchbutton what should happen then? Display the text where?



  • Not sure why this is not working but we have a rule to name GUI controls that you need to refer to in the code, thus radioButton_22 is not acceptable and should be something like radioButton_Interconnect_Yes and the other radioButton_Interconnect_No. Then at least from the code you can see if you refer to the correct radio button without having to go to the designer and find 22...

    So my assumption is that you are actually referring to the correct radio buttons. Then I have no idea why it is not working, it is supposed to.



  • Thanks all,
    It's working now. I renamed the buttons to radioButton_22_Yes etc in the if else statement, took out the connect signal and slots and it worked.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.