Important: Please read the Qt Code of Conduct -

[SOLVED] Having trouble with QRadioButton::setChecked()

  • Hi guys, this is my first time posting. I'm creating an e-Exam program, like the ones they use in some schools to test the students.

    In class MainWindow I have a vector of QRadioButtons, which are used to select the answer. When you click Next or Previous the QRadioButtons change their text to the next or previous question's possible answers respectively. The thing is, when Next or Previous is clicked the program is suppose to uncheck all of the QRadioButtons. It doesn't do that. The problem is in "mainwindow.cpp" on line 54.

    Here's what happens when I run the program. I click any QRadioButton, press Next, the text of all of the QRadioButtons is changed to the next questions possible answers, but the QRadioButton that I clicked is still checked. I would really appreciate it if you guys can help me out.

    Here's the source:

    After you compile it, just drag and drop "sample_test.txt" into the executable.

    Thanks in advance to anyone who replies!

  • Sounds like you are trying to implement "QWizard":

    Have not look into sources yet though.

  • Qt Champions 2017

    Welcome to the forum.

    Issue is Radiobuttons get into exclusive mode. I'm assuming that you are using the the same radiobutton object instances in each page. So once you set into check state, you will not able clear the state. You can do the following work-around.
    You need to find which radio button has been clicked. You can do this in slot using the sender() method. Once you find the radio button, you can do in the example given below. I have just implemented using the Timer to show the functionality.

    @Widget::Widget(QWidget *parent)
    : QWidget(parent)
    QVBoxLayout *lyt = new QVBoxLayout(this);
    but = new QRadioButton("One");
    but1 = new QRadioButton("Two");
    but2 = new QRadioButton("Three");
    void Widget::myslot(){
    qDebug() << "Setting to false"<<endl;



  • @Dheerendra

    Thank you so much! Now everything works!

Log in to reply