QSettings::setValue() replacing custom type with invalid type?
-
Hi, in my application I am storing the settings using settings.ini file format. I have a custom data type that I register and then retrieve and store in the settings.ini file. During the startup, before the custom data type is registered using
qRegisterMetaType
, I callQSettings::setValue()
to set a normal integer value (completely independent from the custom data type) in the settings.ini file. But doing this makes theQSettings
replace all the custom types currently in the settings.ini file with an invalidQVariant
type while debugging the outputQVariant::load: unknown user type with name CustomDataType
, is this behavior normal? -
@CJha The problem is that you can't just replace something in a file if new value has different lenght than the old one. In this case you need to read the file into memory, replace the value and write it back. To read such an ini file and replace something there Qt needs to know how to interpret the data it reads.
-
@CJha said in QSettings::setValue() replacing custom type with invalid type?:
is this behavior normal?
I think so, because at that time you did not yet registered you custom type, right?
-
@CJha
Thinking aloud. In order to do anysetValue()
(or justvalue()
, or any otherQSettings
operation) the Qt code is going to have to read the whole of the.ini
file and parse it correctly. It cannot just "access a single key-value". So it seems reasonable to me that it will fall over if the file contains any unknown custom data type at that point. You really need to call anyqRegisterMetaType()
before you try to access anything in the.ini
file, ISTM. -
@CJha The problem is that you can't just replace something in a file if new value has different lenght than the old one. In this case you need to read the file into memory, replace the value and write it back. To read such an ini file and replace something there Qt needs to know how to interpret the data it reads.
-