PDA

View Full Version : QSettings::setPath don't work?



oficjalne100
17th December 2010, 19:12
Hello
I want set default path to ini file for my program. Default path must be current working directory. So I think that QSettings::setPath is excelent for that. I add following line in main function at very begin in my program (main function):
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, ".");
But it does not work (i don't see the file with settings).
I try also:
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, ".");
But it does not work either.
How to set default path for ini file for my program?

ChrisW67
17th December 2010, 21:56
Works fine here:


#include <QtGui>
#include <QDebug>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, ".");

QSettings s("settings.ini", QSettings::IniFormat);
s.setValue("test", "value");
}



$ cat settings.ini
cat: settings.ini: No such file or directory
$ ./simple_example
$ cat settings.ini
[General]
test=value


Be careful though, the current working directory is a moving target and often not writeable.