Results 1 to 6 of 6

Thread: QSettings vs (QFile + Qtextstream)

  1. #1
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QSettings vs (QFile + Qtextstream)

    for a file with the following format:

    Qt Code:
    1. [Desktop Entry]
    2. Exec="/home/paschim/netbeans-4.1/bin/netbeans"
    3. Terminal=0
    4. Type=Application
    5. Icon=/home/paschim/netbeans-4.1/nb4.1/netbeans.png
    6. Categories=Application;Development;Java;IDE;
    7. Name=NetBeans 4.1
    8. Comment=Launches NetBeans IDE 4.1
    9. Name[ja]=NetBeans 4.1
    10. Comment[ja]=Launches NetBeans IDE 4.1
    11. Name[zh]=NetBeans 4.1
    12. Comment[zh]=Launches NetBeans IDE 4.1
    To copy to clipboard, switch view to plain text mode 

    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?



    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSettings vs (QFile + Qtextstream)

    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.
    J-P Nurmi

  3. #3
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: QSettings vs (QFile + Qtextstream)

    Quote Originally Posted by jpn
    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.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSettings vs (QFile + Qtextstream)

    Quote Originally Posted by nupul
    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.

    Qt Code:
    1. QSettings settings("/home/user/Desktop/.desktop", QSettings::IniFormat);
    2. settings.beginGroup("Desktop Entry");
    3. QString exec = settings.value("Exec").toString();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    nupul (10th April 2006)

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSettings vs (QFile + Qtextstream)

    Quote Originally Posted by nupul
    Why can't i find this path on my installation (Suse 10)???
    http://www.qtcentre.org/forum/showth...=9856#post9856
    J-P Nurmi

  7. #6
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: QSettings vs (QFile + Qtextstream)

    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 '='

    Thanks buddy!

Similar Threads

  1. QFile and QTextStream problems
    By uchennaanyanwu in forum Newbie
    Replies: 0
    Last Post: 7th August 2008, 03:44
  2. Detecting errors with QTextStream and QFile
    By December in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2008, 19:11
  3. QFile, QTextStream
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 12th January 2008, 20:40
  4. QTextStream + QFile issue
    By trueneo in forum Qt Programming
    Replies: 3
    Last Post: 22nd September 2007, 16:16
  5. QFile, QTextStream, seek()
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 29th September 2006, 16:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.