In the Qt QML project, you can use Qt QSettings QML version Settings to facilitate data persistence. For specific use, please refer to the Qt document. Here we will mainly record that no specified file was created after upgrading from Qt 5 to Qt 6. In Qt 5, use the fileName attribute to specify the file path. As follows, the qt_ui_config file can be automatically created under the app folder.
// Qt 5 import 1.0 Settings { id: myAppSettings fileName: applicationDir + "/qt_ui_config" property bool isEdit: false property int menuIndex: 0 property int menuPreIndex: 0 category: "rightMenu" }
After entering Qt 6, the fileName property was deprecated and the location property was used instead, but there was a pitfall. If you just simply modify the property name, you will find that the file cannot be found in the specified directory, but it can be used normally. This is because the prefix must be added to the path after the location property of Qt 6: "file:"
// Qt 6 import QtCore Settings { id: myAppSettings // location: applicationDir + "/qt_ui_config" // failed location: "file:" + applicationDir + "/qt_ui_config" // ok property bool isEdit: false property int menuIndex: 0 property int menuPreIndex: 0 category: "rightMenu" }
This is the article about detailed explanation of Qt6 QML Settings location. This is the end of this article. For more related Qt6 QML. If you do not create a specified path file, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!