Save QRadioButton Selection
-
Hi All,
I am building an application that has a function list connected devices i.e. COM Ports. Now, I have a list of some QRadioButton and they are selected by the user and then I would like to save the user selection state for the next run time.
Could you help me with this issue, as I am not getting the part how can I save users selection for an application?
The nearest functioning example can also be seen in Mouse properties in control panel as user selects the state and apply it. When next time user open the setting it is the last changed state, which user made.
Regards,
Neeraj Singhal -
@Neeraj2020
And to complete @jsulm's answer, to read back & restore the setting, something like (I assume you have your buttons in aQButtonGroup()
):QSettings settings("MySoft", "My App"); QString val = settings.value("ComPorts/selected", "").toString()); if (!val.isEmpty()) { QList<QRadioButton *> buttons = theRadioButtonGroup()->buttons(); for (QRadioButton * button : buttons) if (button->text() == val) button->setChecked(true); }
-
@Neeraj2020 Take a look at https://doc.qt.io/qt-5/qsettings.html
You can store settings in a file and on Windows alternatively in Registry. -
This post is deleted!
-
Hi @sierdzio and @jsulm I read about QSettings but still dont know how to save the the button selection for the user?
I have a list or ports
o COM1
o COM2
o COM3by default, it is on COM1 and now the user open the window and change to COM2 and click OK. Now, next time user opens the window it should be COM2 not COM1.
-
I read about QSettings but still dont know how to save the the button selection for the user
Have you tried any example for QSettings?
-
@Neeraj2020 said in Save QRadioButton Selection:
I read about QSettings but still dont know how to save the the button selection for the user?
Did you try anything already?
There are even examples.
Could be like this:QSettings settings("MySoft", "My App"); settings.setValue("ComPorts/selected", selectedRadioButton->text());
-
@Neeraj2020
And to complete @jsulm's answer, to read back & restore the setting, something like (I assume you have your buttons in aQButtonGroup()
):QSettings settings("MySoft", "My App"); QString val = settings.value("ComPorts/selected", "").toString()); if (!val.isEmpty()) { QList<QRadioButton *> buttons = theRadioButtonGroup()->buttons(); for (QRadioButton * button : buttons) if (button->text() == val) button->setChecked(true); }
-
Thanks to all @sierdzio @jsulm @Pablo-J-Rogina @Denni-0 @JonB