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

Automatic TextField.text property binding is not removed on user input

    XMLWordPrintable

Details

    • Linux/X11

    Description

      Edit: Not related to threading - that part was an error in my reproduction.

       

      When a changed signal is emitted from another Thread - which is thread safe (Edit: unrelated to threads) the would-be-removed property binding still updates the TextField, overwriting any User Input.

       

      FYI in case this needs small changes to compile, I renamed things for the reproduction example here after confirming the bug

      Assume I have a Qt Quick Controls 2 TextField, which auto-binds to MyClass.testProperty

       

      import QtQuick.Controls 2.15
      
      // ....
      
      TextField {
          text: MyClass.testProperty
          height: 64
          width: 200
      }
      

      And a class MyClass, which defines said property, returning a new value every time.

      class MyClass : public QObject
      {
          Q_OBJECT
      public:
          explicit MyClass();
          ~MyClass();
      
          Q_PROPERTY(QString testProperty READ testProperty WRITE setTestProperty NOTIFY testPropertyChanged)
      
          QString testProperty() {
              static int testPropValue = 0;
              return QString::number(testPropValue++);
          };
          void setTestProperty(QString) {
              qInfo("This is not part of the example");
              exit(1);
          };
      
      signals:
          void testPropertyChanged();
      }

      With the class constructor starting a timer on another thread:

       

       

      MyClass::MyClass() : QObject(nullptr)
      {
          auto timer = new QTimer;
          timer->setInterval(2000);
          timer->start(2000);
      
          QObject::connect(timer, &QTimer::timeout, this, &MyClass::testPropertyChanged);
      }

      Which is given to the QmlEngine.:

       

       

      // ...
      qmlAppEngine->rootContext()->setContextProperty("MyClass", new MyClass);
      // ...

       

      I now observe that if I type into the InputField, the contents are still reset to the number every two seconds. 

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            hannes_reports Hannes Duden
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes