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!
#include <QCoreApplication>
#include <QSettings>
#include <QDebug>
int main(int argc, char *argv[])
{
//from the documentation: This function doesn't affect existing QSettings objects.
//Returns the path where settings written using this QSettings object are stored.
qDebug() << settings.fileName();
// debug output: "C:/test/testApp.ini/testOrganization/testAppName.ini"
return a.exec();
}
#include <QCoreApplication>
#include <QSettings>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setOrganizationName("testOrganization");
QCoreApplication::setOrganizationDomain("testOrganization.org");
QCoreApplication::setApplicationName("testAppName");
QCoreApplication::setApplicationVersion("1.2.3.4");
QSettings::setDefaultFormat (QSettings::IniFormat);
//from the documentation: This function doesn't affect existing QSettings objects.
QSettings::setPath(QSettings::Format::IniFormat,QSettings::Scope::UserScope, "c:/test/testApp.ini");
QSettings settings;
//Returns the path where settings written using this QSettings object are stored.
qDebug() << settings.fileName();
// debug output: "C:/test/testApp.ini/testOrganization/testAppName.ini"
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks