PDA

View Full Version : Help with QSettings default constructor



Polnareff
30th September 2010, 23:49
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:


QCoreApplication::setOrganizationName("MyOrg");
QCoreApplication::setApplicationName("MyApp");
QSettings::setPath(QSettings::IniFormat,QSettings: :UserScope,QString(getenv("APPDATA")));

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:


QSettings _Settings;

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:


QSettings _Settings(QSettings::IniFormat,QSettings::UserScop e,"MyOrg","MyApp");

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!

Dan Milburn
1st October 2010, 19:27
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.