@J.Hilk said in Subclass/replace QML Settings:
@RobertB I was expecting it to not want to have a file name and ending. But I'm wrong.
Setpath doesn't seem to have an effect 🤔
QApplication a(argc, argv);
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir d;
d.mkdir(path);
QCoreApplication::setApplicationName("MyApp");
QCoreApplication::setOrganizationName("myOrganization");
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, path);
//QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, path + "settings.ini");
{
QSettings s;
s.setValue("Bla", "Blubb");
s.sync();
qDebug() << s.fileName();
}
qDebug() << path;
returns
"/Users/jhilk/Library/Preferences/com.myorganization.MyApp.plist"
"/Users/jhilk/Library/Application Support/MainWindowTest"
Yes, confusing.
Of course you could:
QSettings("/tmp/test.conf, QSettings::IniFormat, this)
Works as expected. But no way to pass it to Qt.labs.settings 1.0 QML component (pre Qt 5.12.0).
See also the difference between:
Qt 5.9.7 QML settings and Qt 5.12.0 QML settings
Where the Qt 5.9.7 is given no arguments (other than this) and in Qt 5.12.0 you can actually specify your own fileName.
So for now I have backported this QQmlSettings class to Qt 5.9.7 (which BTW was a headache for someone with limited C++ capabilities).