Results 1 to 2 of 2

Thread: Help with QSettings default constructor

  1. #1
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Help with QSettings default constructor

    Hi,

    So in my application I need one QSettings file. In Windows I'd rather use my own regular filepath than the default registry path. I'd also like to be able to use this QSettings across my application without needing to specify the file. Using the QT documentation, I first did the following in my main function:

    Qt Code:
    1. QCoreApplication::setOrganizationName("MyOrg");
    2. QCoreApplication::setApplicationName("MyApp");
    3. QSettings::setPath(QSettings::IniFormat,QSettings::UserScope,QString(getenv("APPDATA")));
    To copy to clipboard, switch view to plain text mode 

    According to the documentation, since I set the organization and app name, when I create an instance without specifying those two, it should use them be default:

    Qt Code:
    1. QSettings _Settings;
    To copy to clipboard, switch view to plain text mode 

    But this doesn't seem to work at all, and I'm not sure where it's saving to. The only time it does actually work is if I specify it each time, as follows:

    Qt Code:
    1. QSettings _Settings(QSettings::IniFormat,QSettings::UserScope,"MyOrg","MyApp");
    To copy to clipboard, switch view to plain text mode 

    Obviously I don't want to do this every time...

    Is there something I'm forgetting, or doing wrong? Or perhaps it's simply not possible to do this...? Thanks!

  2. #2
    Join Date
    Sep 2010
    Posts
    7
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: Help with QSettings default constructor

    The documentation states that the default constructor always uses the default format, which on Windows is the registry. You can change this with QSettings::setDefaultFormat(). My approach would be to have a single QSettings object in your application, accessible through a singleton class.

Similar Threads

  1. QtScript: default constructor question
    By QPlace in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2009, 19:36
  2. Replies: 6
    Last Post: 8th July 2009, 20:28
  3. default parameters in constructor class
    By mickey in forum General Programming
    Replies: 4
    Last Post: 23rd February 2008, 18:44
  4. Q3Frame : no appropraite default constructor available
    By Project25 in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2007, 23:23
  5. What default constructor?
    By bitChanger in forum General Programming
    Replies: 5
    Last Post: 15th February 2006, 19:50

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.