QSettings && insert comment
-
QSettings can use a INI file format, therefore the comments are started by semicolons:
@
; comment
@Btw, notice that QSettings doesn't support comments, therefore if you modify that file with QSettings you'll lose all comments. I think that the point here is that an INI file is an application-oriented format, i.e., you're not supposed to make users change it. If you have to create a config file (and let your users modify it), simply don't use QSettings for it but define a file format of your choice.
-
-
[quote author="Giuseppe D’Angelo" date="1292256187"] If you have to create a config file (and let your users modify it), simply don't use QSettings for it but define a file format of your choice.[/quote]
Thanks,
I know but this way QSettings do the works of retrive data for me... :-)
-
[quote author="peppe" date="1292256187"]If you have to create a config file (and let your users modify it), simply don't use QSettings for it but define a file format of your choice.[/quote]
Could you please suggest any other text-based configuration format that will be more comfortable for hand-editing by user?
Okay, most of the modern apps are GUI-configurable and must simply start and work without any hand-configuration by user. But this is not a case for all apps, just for most ;)
[quote author="Luca" date="1292256437"]I know but this way QSettings do the works of retrive data for me... :-)[/quote]
Maybe the better solution would be just to install the default commented-by-hands configuration file with your app? Definitely the stupidiest way to solve this problem but it should work :)
-
I'm very familiar with some linux configuration files and QSettings config file is similar.
For example mysql server configuration file is :
@The following options will be passed to all MySQL clients
[client]
...
...
#password = your_password
port = 3306
socket = /var/run/mysql/mysql.sockHere follows entries for some specific programs
The MySQL server
[mysqld]
port = 3306
socket = /var/run/mysql/mysql.sock
...
...
@and as you can see the comments are started with # .
Using QSettings I can have a similar configuration file without difficult. ;-)
-
[quote author="Bobs" date="1292506729"][quote author="peppe" date="1292256187"]If you have to create a config file (and let your users modify it), simply don't use QSettings for it but define a file format of your choice.[/quote]
Could you please suggest any other text-based configuration format that will be more comfortable for hand-editing by user?
Okay, most of the modern apps are GUI-configurable and must simply start and work without any hand-configuration by user. But this is not a case for all apps, just for most ;)
[/quote]My point wasn't "INI files have a bad syntax" / "users are not comfortable with them"; I was only pointing out that reading and writing an INI file with QSettings would wipe out all comments, because INI is application-oriented and not human-oriented. That's it :-) If your file is a readonly configuration file, QSettings can save the day! (Although be very careful, since AFAIK there's no way of telling QSettings to never modify the file).
If you're looking for other formats, well, it really depends on what you're doing, but key/value based files like
@
key = value
@
are handled easily with QTextStream and QString methods. -
[quote author="peppe" date="1292511851"]I was only pointing out that reading and writing an INI file with QSettings would wipe out all comments, because INI is application-oriented and not human-oriented. That's it :-)[/quote]
Okay, sure. But (just as "IMHO") I really don't know any more human-oriented formats than INI for that case :)[quote author="peppe" date="1292511851"]If your file is a readonly configuration file, QSettings can save the day! (Although be very careful, since AFAIK there's no way of telling QSettings to never modify the file).[/quote]
Yep, but I've tried it in a rather big linux only project. It doesn't wipe anything as long, as we're not trying to write any settings to the file :) -
I update this post because now with Qt 4.7.1 the sharp comment (#) doesn't works as comment.
I have a settings file like this:
@
[Allarmi]
22\descrizione=text1
22\descrizione1=text2
;701\descrizione=text3
;702\descrizione=text4
#800\descrizione=text5
#800\descrizione1=text6
@But # isn't commented out.
If I do:
@
QStringList lista_id_dati_allarmi;
lista_id_dati_allarmi = setting->childGroups();
qDebug() << lista_id_dati_allarmi;
@I get:
@
("#800", "22")
@I don't know what's wrong but I remember that with previous Qt version the # comment was recognized as comment.
Is it possible or am I out of mind...?
-
I try on Qt 4.7.2 now and work well for me.
[quote author="Luca" date="1306854471"]
[quote author="stuk" date="1306854390"]I remember Qt don't understand the comment if you use write on the qsetting file. I use comment only in a read-only file.[/quote]Mine is a read-only file. I edit it by hand.
[/quote] -