- changed milestone to 1.9.0
refactor: replace pickle files by QSettings
We have used pickle files to remember QT states of the applications. This could be changed to the builtin QSettings an example on:
Comments (10)
-
reporter -
reporter - changed milestone to 1.8.0
-
After resolving issue
#254with PR#625, I am looking forward to work on this. -
I realize a few things, and this change might do more harm than good in a long run.
For example, this is a sample script to work with QSettings if we have array with diverse datatypes.
save data
settings_const = { 'a': "asdfasdf", 'b': True, 'c': [1,23,4,'asdf'] } for key in settings_const.keys(): if type(settings_const[key]).__name__ == 'list': q_settings.beginWriteArray(key) for i in range(len(settings_const[key])): q_settings.setArrayIndex(i) q_settings.setValue("value", settings_const[key][i]) q_settings.endArray() else: q_settings.setValue(key, settings_const[key]) q_settings.sync()
get data
# with _fs.open(_name, "rb") as fileobj: # settings = pickle.load(fileobj) # logging.debug(settings) child_keys = q_settings.childKeys() for key in child_keys: value = q_settings.value(key) if value == "true": settings[key] = True elif value == "false": settings[key] = False else: settings[key] = value all_keys = q_settings.allKeys() array_keys = getArrayKey(all_keys) key = array_keys[0] settings[key] = [] print(array_keys) size = q_settings.beginReadArray(key) for i in range(size): print("reached here2") q_settings.setArrayIndex(i) val = q_settings.value("value") try: val = int(val) except: pass settings[key].append(val) q_settings.endArray() print(settings)
This process would get inefficient as more complex data gets stored in QSettings.
-
I might be wrong, as I am new to both Qt and MSS. But if these doubts are cleared, I have the rest of the code almost ready for a pull request.
-
reporter I'm not tried that but I guess we can build hierarchical groups on dictionaries
e.g.
https://stackoverflow.com/questions/18870057/having-hierarchical-groups-in-ini-file-for-qsettings
the data type could be retrieved that way: https://stackoverflow.com/questions/9257422/how-to-get-the-original-python-data-from-qvariant
interesting discussion too: https://stackoverflow.com/questions/13729189/is-it-possible-to-pickle-a-qsettings-object
The different types are still an issue.
How much data will that become?
-
QVariant seems to handle complex dictionaries as well, and list with multiple datatype. Bool seems to be stored as string but that's no biggie.
-
I will push the PR soon.
-
reporter - changed status to resolved
Fixes issue
#325, shift to QSettings from pickle to save state of application→ <<cset e5bee0a3aa40>>
-
reporter Merged in plant99/mss/i325-m (pull request #628)
Fixes issue
#325, shift to QSettings from pickle to save state of application→ <<cset 595aec9ed7ec>>
- Log in to comment