QML Settings doesn't have "remove" function !
-
Hi
I have some settings in my app, which it's parameters are stored in a file, usingSetting
API. I can save and load parameters, but need to remove them, sometimes; Like QSettings::remove() in C++.
But it seems there is no such function in QML API of Settings.How it is possible?
-
@Mohammadsm
i havent tried yet, but i guess in QML you only have two values to assign which might unset the value.undefined
andnull
worth a try at least
on the other hand i dont think its possible to remove the whole property from the object itself, after creation -
It's not about property, I mean removing a key from a
Settings
object:
https://doc.qt.io/qt-5/qsettings.html#remove
But doing this in QML.Settings
in QtQuick, doesn't have remove method :(
https://doc.qt.io/qt-5/qml-qt-labs-settings-settings.html#methodsI need to remove a key from
Settings
object.Thank you for responding
-
@Mohammadsm said in QML Settings doesn't have "remove" function !:
It's not about property, I mean removing a key from a Settings object:
iitt is, since in the QML Settings type the keys are taken from the properties
-
It didn't worked :(
I tried:setting.setValue("step_1", null)
but the
app.conf
shows:
[General]
step_1=@Variant(\0\0\0\x94)
and
setting.setValue("step_1", undefined)
makes:
[General]
step_1=@Invalid()
They don't remove 'step_1' from
app.conf
file! -
Which variable do you want to remove from your settings?
Entire Group or child key or file which contains some config?
-
@Mohammadsm
QSettings is technically still part of the labs import and not really considered production ready (may change become incompatible at any moment)So, this seems like a perfect opportunity to make a feature request at https://bugreports.qt.io/secure/Dashboard.jspa
meanwhile,
I suggest subclassing QSettings, and making the remove function Q_INVOKABLE and exposing that new class for your use in QML -
@Munkhtamir
I want to remove "step_1" which is a key in mySettings
object:Settings{ id: stg } . . . stg.setValue("step_1", 127)
-
@J-Hilk
I managed the required behavior, somehow.By blanking the key value:
stg.setValue("step_1", "")
then scanning the keys, which have non-empty value, and skipping the empty ones.
I'll file a bug, cause I think it's a needed method!
By the way, thank you all