PDA

View Full Version : Problem with QSettings - failure to store ini in custom directory



TorAn
12th January 2019, 13:51
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[])
{
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,QS ettings::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();
}

Lesiok
12th January 2019, 14:24
QSettings::setPath sets directory not file. Maybe you should use the right version of the constructor :
QSettings settings("C:/blabla/bleble.ini",QSettings::IniFormat);

TorAn
12th January 2019, 17:34
Shame on me :(