Keeping track of user Preferences
What is the best way to keep track of user preferences in an easy way to retrieve later? Would a xml file work best?
See QSettings object: http://doc.qt.nokia.com/4.7/qsettings.html
"The QSettings class provides persistent platform-independent application settings ... This information is often stored in the system registry on Windows, and in XML preferences files on Mac OS X."
You can also keep the settings in your application directory using .ini file, see ::setPath():
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, qApp.applicationDirPath() + "/");
Can I use these QT commands directly alongside my QML? Sorry if this exposes my ignorance.
[quote author="kyleplattner" date="1290476695"]Can I use these QT commands directly alongside my QML?[/quote]
It is possible. You find more information about it in "this part of the docs":http://doc.qt.nokia.com/4.7/qtbinding.html#calling-c-methods-from-qml
[quote author="kyleplattner" date="1290476695"]
Sorry if this exposes my ignorance.[/quote]
Don't need to say that, DevNet is a place to learn and share knowledge. Follow the doc I posted above and ask here if you have any problem. :-)
Is there no way to store settings (ala QSettings) without resorting to C++? I want my app to be completely portable - ie without recompiling - and so want to do it all in QML. I've so far managed to do this for the main functionality of my app, and it would seem stupid to introduce C++ just for settings.
...or should I be looking to use PySide instead?
When working with QML, I would go with one of these options:
the "data storage":http://doc.qt.nokia.com/4.7/qdeclarativeglobalobject.html#offline-storage-api facility that is in there by default
create a custom QObject (in C++) that has properties for the settings you wish to store, and use QSettings in that object to store them. You can export the an instance of this object to your QML context.
ok, thanks. I was really hoping for something like QSettings - it's really simple - but I guess the data storage is good enough.
I really want to avoid C++ since I've done the rest of my app in QML and don't want to have to build for multiple platforms just to get QSettings.
I did some Android development, and I used qml for the settings there, so I guess it is an acceptable solution. It's a little irritating not to have QSettings, but anyway...
Well, it seems like a useful suggestion to me to add such an Element to QML. Why don't you file a suggestion in "Jira":http://bugreports.qt.nokia.com for it?
ok, I will look into that (I kind of expect it will already be there, but anyway)...
Hi can any one please provide me with some example using QSettings with c++ and QML
I am also looking for a good example, or the Qt-recommended way, of getting settings into a QML app with a C++ back-end. The settings will have to be passed to the C++ code (or better, read directly from the C++ code -- like you can do with "sprinkling" QSettings everywhere for different classes that read the same settings -- which saves the need for passing settings as parameters), and read and edited (through forms) with QML code.
I found this, which is a start, but I'd like to hear if there are better ways.