Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.7.0
-
None
-
qtquickcontrols2: 05933f155e0f0e90fb609839688e01b05d8e80ae
Description
Unfortunately Settings (Qt.labs.settings) cannot be used inside the component.
Real problems happen when you try to use Settings inside the qml document which is instantiated inside Component. Take a look at small example:
main.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 import Qt.labs.settings 1.0 ApplicationWindow { visible: true StackView { id: stackView anchors.fill: parent initialItem: thePage } Component { id: thePage Page { Settings { id: settings property int theNumber: -1 } Component.onDestruction: { settings.theNumber = 42 console.log("onDestruction") } } } }
Configuration file will never contain "42" as "theNumber" value, it is always "-1". The "onDestruction" handler is called, but settings are not saved by some reason. If you remove configuration file while program is running, this configuration file is not recreated when program finishes.
Obviously, moving Settings outside the Component fixes the problem. But in real use-case the Component is far away from the main.qml files and it would be nice to declare its own settings close to the implementation.
Attachments
For Gerrit Dashboard: QTBUG-54552 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
165316,2 | QQuickStackView: claim QObject ownership for dynamically created items | 5.7 | qt/qtquickcontrols2 | Status: MERGED | +2 | 0 |