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

Binding is not working when 'value' goes to null.

    XMLWordPrintable

Details

    • da14688140550879e376e71cf273b16494e6c3c4

    Description

      myWindow.text and qmlWindow.text is not changed, while root.value is changed to 'null' from some value.

      What I expected myWindow.text and qmlWindow.text are also updated through the Bindings.

       

      Test code.

       

      main.cpp

       

      #include <QGuiApplication>
      #include <QQuickView>
      #include <QQmlContext>
      
      class MyView: public QQuickView
      {
          Q_OBJECT
          Q_PROPERTY(QObject *test READ test WRITE setTest NOTIFY testChanged)
      
      public:
          void init() { rootContext()->setContextProperty(QLatin1String("myWindow"), this); }
          QObject *test() { return m_test; }
          void setTest(QObject *t) { qInfo() << "setTest" << t << m_test; m_test = t; emit testChanged();}
      
      signals:
          void testChanged();
      
      private:
          QObject *m_test = nullptr;
      };
      
      int main(int argc, char *argv[])
      {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
          QGuiApplication app(argc, argv);
      
          const QUrl url(QStringLiteral("qrc:/main.qml"));
      
          MyView view;
          view.init();
          view.setSource(url);
          view.show();
      
          return app.exec();
      }
      
      #include "main.moc"
      
      
      import QtQuick 2.12
      import QtQuick.Window 2.12
      
      Rectangle {
          id: root
          visible: true
          width: 640
          height: 480    
          color: "red"
          property var myValue: -1
      
      
          MouseArea {
              anchors.fill: parent
              onClicked: { root.toggle(); }
          }
      
      
          function toggle() {
              if (root.myValue == null) {
                  root.color = "yellow"
                  console.log("set to root")
                  root.myValue = root
              } else {
                  root.color = "red"
                  console.log("set to null")
                  root.myValue = null
              }
          }
      
          Item {
              id: qmlWindow
              property var test: null
              onTestChanged: console.log("qmlWindow", test)
          }
      
          Binding {
              target: myWindow
              property: "test"
              value: root.myValue
          }
      
          Binding {
              target: qmlWindow
              property: "test"
              value: root.myValue
          }
      }
      
      

       

       

       

      Attachments

        Issue Links

          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
              elvis Elvis Lee
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes