Nominate our 2022 Qt Champions!

How to map QRadioButtons to a QDataWidgetMapper

  • I have two radio buttons in a QGropBox, grouped together in one group.
    So, haw can I map them to a mapper?
    I 'll put: mapper->..and then what?

    They must be mapped o a field from db, named paid.
    When paid is 1, I want radio1 to be checked (and radio 2 unchecked).
    When paid is 0 or empty, I want radio2 to be checked (and radio 1 unchecked).

  • I found this, works for reading the QRadioButtons.
    But the value of the Radio group does not get stored in the database.
    How can I add this feature? (I mean without using model->setData method)

  • Lifetime Qt Champion


    Do you mean the the mapper doesn't update the model ?

  • I don't know if the mapper updates the model(can I check this somehow?).
    I only know that db does not get updated.(when I m not using the setData)
    (let me explain: I use model->setData() to insert the RadioGroup 's value in the model. Works fine and gets saved in db. I was just thinking if it 's possible to remove model->setData(), modifying, somehow, the code of the class OptionGroup)

  • I want to make a function clear() in the class OptionGroup, which will set all Radio buttons of the Group to false.
    This is the code in the function, but does not set Radio buttons to false. It does nothing:

        foreach (QRadioButton *RadioButton, buttonMap_){
            qDebug()<< RadioButton->objectName();
        currentSelection_ = false;
        emit selectionChanged(currentSelection_);

    How can I do this?

  • Lifetime Qt Champion

  • Thanks! setAutoExclusive did the job.

Log in to reply