Results 1 to 6 of 6

Thread: QSettings::setPath()

  1. #1
    Join Date
    Mar 2006
    Posts
    74
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default QSettings::setPath()

    On Qt3 I have my QSettings object setup this way:

    Qt Code:
    1. mySettings = new QSettings();
    2. mySettings->setPath( "myOrg", "myApp", QSettings::User);
    3. mySettings->insertSearchPath( QSettings::Unix, QDir::homeDirPath() + myBaseDir + "/config" );
    To copy to clipboard, switch view to plain text mode 

    Looking at the Qt4 docs it looks like:

    Qt Code:
    1. mySettings = new QSettings("myOrg", "myApp");
    2. mySettings->setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homeDirPath() + myBaseDir + "/config");
    To copy to clipboard, switch view to plain text mode 

    Should do exactly the same thing but it does not. For some reason the path parameter of the of the call to QSettings::setaPath(format, scope, path) call does not do anything. How do I get this to use the path I specify for the location of the configuration file? Seems kind of strange that the Trolls would have a parameter on a call that does not do anything. So either the documentation is wrong or there is something about this that I don't understand. Anyone know what is going on with this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QSettings::setPath()

    QSettings::setPath() is a static method and you have to invoke it before you create QSettings instance.

    Qt docs say:
    Warning: This function doesn't affect existing QSettings objects.

  3. #3
    Join Date
    Mar 2006
    Posts
    74
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default Re: QSettings::setPath() (solved)

    Yes I saw that but I was not sure what that meant? Are you saying that when my code says:

    mySettings = new QSettings("myOrg", "myApp");

    that at that point it is an existing QSettings object and that I need to call QSettings::setPath() before the QSettings object is instantiated? On the surface this does not make sense. After all how can you call a method for an object that does not exist? But I just did a test and it worked although somewhat differently than it does in Qt3.

    So it appears that it is expecting:

    Qt Code:
    1. mySettings -> setPath(,,,); // mySettings is not a valid object
    2. // QSettings::setPath(...) also works
    3. mySettings = new QSettings(...);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QSettings::setPath() (solved)

    Quote Originally Posted by hvengel View Post
    After all how can you call a method for an object that does not exist?
    setPath() is a static method, so it doesn't need any instances.

    Quote Originally Posted by hvengel View Post
    mySettings -> setPath(,,,); // mySettings is not a valid object
    // QSettings::setPath(...) also works
    The proper way to invoke a static method is "QSettings::setPath(...);".

    "invalidPtr->setPath(...)" works, but that's a very bad programming style.

  5. #5
    Join Date
    Nov 2007
    Posts
    89
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 21 Times in 18 Posts

    Default Re: QSettings::setPath()

    You should use QSettings::IniFormat instead of QSettings::NativeFormat, because on Windows native format is registry and also in Mac Os X it doesn't use files.

  6. #6
    Join Date
    Mar 2006
    Posts
    74
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default Re: QSettings::setPath()

    I know that. I want to use the native format on each platform.

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
  •  
Qt is a trademark of The Qt Company.