QSettings && insert comment
-
wrote on 13 Dec 2010, 15:41 last edited by
Hi all,
in my application I use a QSettings file to enable users to insert some parameter (by passing a text file as QSettings(filename) ).Sometimes I need to insert some comment string in the qsettings file to help users to use the right sintax.
What kind of comment character should I use?
Is it the same of c++ comment ( // /* ecc.. ) ? -
wrote on 13 Dec 2010, 15:53 last edited by
I think you cannot use QSetting with comment.
I use #comment to manual QSetting file, but when i modify the file with the function of QSetting it delete my comment.
If you only parse the qsetting you can use #, if you write on you can't. -
wrote on 13 Dec 2010, 16:02 last edited by
Thanks,
my qsettings file is read only so # should help .
Have you found '#' in the documentation ? -
wrote on 13 Dec 2010, 16:03 last edited by
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.
-
wrote on 13 Dec 2010, 16:04 last edited by
No, becouse QSettings not support comment, this is a trick for read only files (or manually editing).
[quote author="Luca" date="1292256143"]Thanks,
my qsettings file is read only so # should help .
Have you found '#' in the documentation ?[/quote] -
wrote on 13 Dec 2010, 16:07 last edited by
[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... :-)
-
wrote on 16 Dec 2010, 13:38 last edited by
[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 :)
-
wrote on 16 Dec 2010, 13:52 last edited by
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. ;-)
-
wrote on 16 Dec 2010, 15:04 last edited by
[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. -
wrote on 16 Dec 2010, 17:55 last edited by
[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 :) -
wrote on 31 May 2011, 12:52 last edited by
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...?
-
wrote on 31 May 2011, 15:06 last edited by
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.
-
wrote on 31 May 2011, 15:07 last edited by
[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.
-
wrote on 31 May 2011, 15:16 last edited by
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] -
wrote on 6 Jun 2011, 09:41 last edited by
[quote author="stuk" date="1306854962"]I try on Qt 4.7.2 now and work well for me.
[/quote]
You mean that using sharp (#) in a qsettings file excludes the line ?
-
wrote on 6 Jun 2011, 12:08 last edited by
Yes, using # work for me on windows.
[quote author="Luca" date="1307353306"]
[quote author="stuk" date="1306854962"]I try on Qt 4.7.2 now and work well for me.[/quote]
You mean that using sharp (#) in a qsettings file excludes the line ?[/quote]
-
wrote on 6 Jun 2011, 12:11 last edited by
[quote author="stuk" date="1307362137"]Yes, using # work for me on windows.
[/quote]
Ok, thanks.
Unfortunately it doesn't works in Linux... it seems...