PDA

View Full Version : QSettings vs (QFile + Qtextstream)



nupul
8th April 2006, 05:49
for a file with the following format:




[Desktop Entry]
Exec="/home/paschim/netbeans-4.1/bin/netbeans"
Terminal=0
Type=Application
Icon=/home/paschim/netbeans-4.1/nb4.1/netbeans.png
Categories=Application;Development;Java;IDE;
Name=NetBeans 4.1
Comment=Launches NetBeans IDE 4.1
Name[ja]=NetBeans 4.1
Comment[ja]=Launches NetBeans IDE 4.1
Name[zh]=NetBeans 4.1
Comment[zh]=Launches NetBeans IDE 4.1



The above is a .desktop file for Netbeans installed on my Linux/KDE distro.

For files with such formats what is the best way to access them: using QSettings or Qfile and Qtextstream?

:confused:

For which type of files should one choose the either of the above methods? will be helpful if you could also highlight the tradeoffs involved.

Can I read a file with QSettings, which has been hand coded and NOT written by any program before....Please give me an example of how to read any value from the above file.

Thanks

Nupul

jpn
8th April 2006, 10:49
I'm not sure if you really can parse a specific ini file with QSettings (you could try playing with QSettings::setPath).
If that doesn't work, take a look at QConfFileSettingsPrivate::readIniFile() in src/corelib/io/qsettings.cpp.

nupul
10th April 2006, 07:16
I'm not sure if you really can parse a specific ini file with QSettings


Why not? The file format is similar as how QSettings would store it, right?



If that doesn't work, take a look at QConfFileSettingsPrivate::readIniFile() in src/corelib/io/qsettings.cpp.

Why can't i find this path on my installation (Suse 10)???

Thanks.

jpn
10th April 2006, 07:51
Why not? The file format is similar as how QSettings would store it, right?
My mistake. The format is no problem at all. But I thought that QSettings would possibly do some assumptions about the path, eg. it's restricted to either $HOME/.config (user scope) or /etc/xdg (system scope) in *nix so you couldn't parse whichever file you want. But that seems not to be the case.



QSettings settings("/home/user/Desktop/.desktop", QSettings::IniFormat);
settings.beginGroup("Desktop Entry");
QString exec = settings.value("Exec").toString();

jpn
10th April 2006, 08:08
Why can't i find this path on my installation (Suse 10)???
http://www.qtcentre.org/forum/showthread.php?p=9856#post9856

nupul
10th April 2006, 08:26
Which implies that it is always preferable to use QSettings for such files, right?

As the code you put forth is simpler and more elegant than using Qfile and Qtextstream and splitting the string on '=' :eek:

Thanks buddy!