Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

MULTIPLE CHOICE QUIZ WITH QRADIOBUTTON



  • Hi, am creating a multi choice program I have many questions. I have used some radiobuttons, when I want to move to the next question I just use the setText() of the
    Qradiobutton. However, the option the user chose from the previous question remains checked.
    I have tried creating an array of radio button objects,however I didn't succeeded as I was using replaceWidget() of QLayout to change them any help please?


  • Lifetime Qt Champion

    Hi,

    You should consider having a "reset" method that will put the widget back in some initial state.

    You might want to also check QWizard for that kind of scenario.

    On a side note, please avoid all uppercased title, in written language it is considered shouting and rude.



  • @SGaist
    Thanks, I have taken note of uppercase i was ignorant of that.
    I still have a challenge
    I created a QStackedWidget and then I added *widgets[50] to it, to each of the widgets I added 4 radiobuttons . at the last page of the widget when I want to check which radio button was checked it doesn't work .


  • Lifetime Qt Champion

    @gblessed said in MULTIPLE CHOICE QUIZ WITH QRADIOBUTTON:

    when I want to check which radio button was checked it doesn't work .

    then please show how you're doing that



  • @jsulm
    In my header

    QStackedWidget *stacked = new QStackedWidget;
    QRadioButton * radio[200];
    QVBoxLayout *paged[50];
    QWidget *wiggy[50];
     
    //main window.cp
    int kj=0;
    for(int i=0; i<50; i++)
    { into 
    wiggy[i] = new QWidget();
    paged[i] = new QVBoxLayout;
    wiggy [i]->setLayout[paged[I];
    for(int j=0; j<4; j++){
    radio [kj] = new RadioButton(text);
    paged[i]->addWidget(radio [kj]);
    kj++;
    }
    
    }
    
    void on_pushbuttonclicked(){
    for(int i=0; i<200; i++){
    
    if(radio[i]->is checked())
    qDebug()<<"checked";
    }
    
    }
    

  • Lifetime Qt Champion

    @gblessed said in MULTIPLE CHOICE QUIZ WITH QRADIOBUTTON:

    radio [kj] = new RadioButton(text);

    Do you mean QRadioButton? Or is it your own class?
    Is any of the radio buttons checked when you press the button?



  • @jsulm sorry I meant QRadioButton
    None of the Radio buttons is checked however, if I connect the clicked(bool) signal of the QRadioButton to a slot, it works.


Log in to reply