Results 1 to 3 of 3

Thread: Problem with QSettings - failure to store ini in custom directory

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    206
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with QSettings - failure to store ini in custom directory

    I am upgrading my old application to store app settings in user-specified directory.
    Previously I stored it in "default" location, whatever this location is and I did not care.
    Now I do care and quickly changed the code to store settings in user-specified directly. Did not work.

    I could not figure out what is wrong with the code. I wrote a test to illustrate the problem I am having.
    Please see the debug output - it appends organization name and domain to the specified path. WTF?
    It is so counter-intuitive.

    I can't change organization name etc, the app should support "old" and "new" ways. So, my questions are:
    1. Perhaps I am doing something wrong. What it might be?
    2. Is there a way to store ini file in specific directly in the case shown in the test below?

    Thanks in advance!

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QSettings>
    3. #include <QDebug>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QCoreApplication a(argc, argv);
    8.  
    9. QCoreApplication::setOrganizationName("testOrganization");
    10. QCoreApplication::setOrganizationDomain("testOrganization.org");
    11. QCoreApplication::setApplicationName("testAppName");
    12. QCoreApplication::setApplicationVersion("1.2.3.4");
    13. QSettings::setDefaultFormat (QSettings::IniFormat);
    14.  
    15. //from the documentation: This function doesn't affect existing QSettings objects.
    16. QSettings::setPath(QSettings::Format::IniFormat,QSettings::Scope::UserScope, "c:/test/testApp.ini");
    17.  
    18. QSettings settings;
    19. //Returns the path where settings written using this QSettings object are stored.
    20. qDebug() << settings.fileName();
    21.  
    22. // debug output: "C:/test/testApp.ini/testOrganization/testAppName.ini"
    23.  
    24.  
    25. return a.exec();
    26. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,416
    Thanked 258 Times in 253 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QSettings - failure to store ini in custom directory

    QSettings::setPath sets directory not file. Maybe you should use the right version of the constructor :
    Qt Code:
    1. QSettings settings("C:/blabla/bleble.ini",QSettings::IniFormat);
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lesiok; 12th January 2019 at 15:35.

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

    TorAn (12th January 2019)

  4. #3
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    206
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QSettings - failure to store ini in custom directory

    Shame on me

Similar Threads

  1. Store and load passwords via QSettings
    By ralfwickum in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2015, 15:18
  2. QSettings custom class serialization problem
    By sakya in forum Qt Programming
    Replies: 1
    Last Post: 19th December 2011, 12:00
  3. store QSettings in XML for all platforms wanted
    By nilir in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2010, 10:50
  4. Replies: 6
    Last Post: 5th December 2009, 15:46
  5. Store an custom enum in QSettings
    By Lykurg in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2007, 21:06

Tags for this Thread

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.