Results 1 to 2 of 2

Thread: QSettings::setPath don't work?

  1. #1
    Join Date
    Dec 2010
    Posts
    28
    Thanks
    6
    Thanked 10 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QSettings::setPath don't work?

    Hello
    I want set default path to ini file for my program. Default path must be current working directory. So I think that QSettings::setPath is excelent for that. I add following line in main function at very begin in my program (main function):
    QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, ".");
    But it does not work (i don't see the file with settings).
    I try also:
    QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, ".");
    But it does not work either.
    How to set default path for ini file for my program?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSettings::setPath don't work?

    Works fine here:
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, ".");
    9.  
    10. QSettings s("settings.ini", QSettings::IniFormat);
    11. s.setValue("test", "value");
    12. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. $ cat settings.ini
    2. cat: settings.ini: No such file or directory
    3. $ ./simple_example
    4. $ cat settings.ini
    5. [General]
    6. test=value
    To copy to clipboard, switch view to plain text mode 

    Be careful though, the current working directory is a moving target and often not writeable.

  3. The following user says thank you to ChrisW67 for this useful post:

    oficjalne100 (18th December 2010)

Similar Threads

  1. how to use Qsettings
    By elDua in forum Newbie
    Replies: 1
    Last Post: 5th August 2010, 21:22
  2. Replies: 2
    Last Post: 13th December 2009, 20:27
  3. QSettings setPath Scope
    By philwinder in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2008, 21:09
  4. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 03:21
  5. QSettings::setPath()
    By hvengel in forum Qt Programming
    Replies: 5
    Last Post: 21st February 2008, 00:37

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.