Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89221

QQmlEngine::retranslate() reactivates dead binding

    XMLWordPrintable

Details

    • All

    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 )

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            adrian.gabureanu Adrian Gabureanu
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes