Skip to content
Advertisement

Saving states of QRadioButtons using QSettings not persisting values correctly in PyQt5

I’m baffled by the results of using QSettings to save the state of my radio buttons from one app session to another using PyQt5. (OS = Ubuntu Linux 18.04)

These are the steps to produce baffling results:

  1. Run the app; see both radio buttons selected; both buttons fire as if mouse selected
  2. Deselect the top radio button
  3. Close the app; see the ‘correct’ saving of the radio button checked states
  4. Run the app; both radio buttons are selected even though different states were saved where only one button is selected
  5. Deselect the top radio button
  6. Close the app; see the ‘correct’ saving of the radio button checked states
  7. In the code, in line 18, change QSettings('LoneProgrammer2', 'qsettingsTest1') to QSettings('ChangeThis', 'qsettingsTest1'); save the code
  8. Run the app; !!The correct saved values are reflected by the radio button selection!!
  9. Close the app; 10 Run the app and now there are two radio buttons selected again!

Can anyone please explain what’s going on here? I just want the QSettings to work.

JavaScript

Advertisement

Answer

When reading settings values it is good to indicate the type as there may be confusion (most likely value will return the strings “true” and “false” that are converted to True when using bool since they are truly). On the other hand to add readability it is better to create specialized methods.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement