[SOLVED] Application settings for multiple versions on same machine



  • I am new to Qt after being told by a friend to try it out for a cross platform widget toolkit. I am using Qt Creator for coding, and but making use of CMake due to encountering limitations of QMake (which is great for simple structured applications). I also decide to use QML for fast prototyping development work, and I am totally amazed at the speed I can develop, constantly adding new bits and features.

    I having difficulty with application settings with different versions.

    I using QSettings class to handle the application settings, and have set QApplication's name, domain, and version properties before creating the QSettings object. I see the <application name>.ini being created under <domain name> directory, but it is being used by all the different versions of the application. This is causing problems when I running different versions, as some of settings have undergone changes between application versions. I seen various applications simply include the version numbers as part of the application directory name, and within the directory have settings .ini file with no version number as part of filename. Though Qt seem not to use directory for application settings container.

    How do I get QSettings to create a setting .ini file that includes the application version in the file name? For example app-0.5.ini and not just app.ini, so I can have settings app-0.5.ini and app-0.6.ini for application version 0.5 and 0.6.

    Also need to access the correct version settings file from QML. I can't see or figure out how to specify the settings file to use. I am using the Qt.application properties in About dialog window and other locations. I currently using Qt.labs.settings 1.0.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK, you can't do it using a default constructed QSettings object however you should be able to do what you want using this constructor. Just concatenate the application and it's version number when creating the QSettings object and you should be good to go.

    Hope it helps



  • Thanx, this worked in creating and using the version based settings file in the C++ part of the application.

    Now I still have the issue with QML part to read the correct settings file. I can't seem to see anything in how to specify the application name, version, and domain. Currently nothing is being read, and I suspecting it is not finding the settings file for a specific application version.

    Documentation on Settings for QML is rather vague.



  • Excellent news. I finally got a solution after plenty googling.

    Based on this post I manage to make a Settings object (extending QSettings) that uses the correct version of the application settings for QML part.

    Now both the C++ part and the QML part are accessing the correct version settings file.

    Remember: not to import Qt.labs.settings 1.0 as it will overwrite Settings object.


  • Lifetime Qt Champion

    Nice ! Thanks for sharing :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.