Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
5.15.2
Description
I have a setup involving QML Settings and QQmlEngine::retranslate().
property int _defaultValue: 100 property int myValue: _defaultValue Settings{ property alias myValue: root.myValue }
If I modify myValue myself, then retranslate leaves myValue unchanged.
If I let Settings restore the value, then retranslate changes myValue to _defaultValue.
Expected: If there's a value to be restored from Settings, restoring that value should also break the binding.
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); app.setOrganizationName("OrganizationName"); app.setOrganizationDomain("OrganizationDomain.com"); QQmlApplicationEngine engine; qmlRegisterSingletonInstance("com.domain.core",1,0,"Engine", &engine ); const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
main.qml
import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Controls 2.15 import Qt.labs.settings 1.1 import com.domain.core 1.0 Window { id: root width: 640 height: 480 visible: true title: qsTr("Hello World") property int _defaultValue: 100 property int myValue: _defaultValue Settings{ property alias myValue: root.myValue } Text{ id: t1 text: "myValue:"+myValue anchors.centerIn: parent } Button{ id: b1 text: "myValue--" anchors{ top: t1.bottom topMargin: t1.height horizontalCenter: t1.horizontalCenter } onClicked: myValue--; } Button{ id: b2 text: "QQmlEngine::retranslate()" anchors{ top: b1.bottom topMargin: b1.height horizontalCenter: b1.horizontalCenter } onClicked: Engine.retranslate(); } }
STEPS TO REPRODUCE:
1) Run the App.
2) Press "myValue--".
3) Exit the App.
4) Reopen the App.
5) Press "QQmlEngine::retranslate()"
6) myValue is restored to _defaultValue:100 (BUG -> retranslate shouldn't change this value )