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

Only the first Q_PROPERTY marked as REQUIRED is required in reality

    XMLWordPrintable

Details

    • 6f36faf96b488330f2388bdc8728d843f14c38f9 (qt/qtdeclarative/dev) 2b88f43894a068dc288c813b291e2ac05f8e4782 (qt/qtdeclarative/6.2)

    Description

      If a class has a number of Q_PROPERTYs only the first REQUIRED property seems to be required for instantiating the object in Qml. So in a setup where there are 2 properties e.g.

        Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged REQUIRED)
        Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged REQUIRED)

      setting the property "index" in Qml seems to be enough for the object to be successfully instantiated.

          Demo {
              id: demo
              index: 1
              Component.onCompleted: {
                  console.log("The property 'name' is required but it's value is:", demo.name)
              }
          }

      If the order of the Q_PROPERTYs is swapped in C++ and the test app is rebuilt now there would be an error

      QQmlApplicationEngine failed to create component
      qrc:/main.qml:10:5: Required property name was not initialized

      upon running the test app.

      Steps to reproduce the problem:

      1. run the attached example (it loads the qml without any warnings or errors)

       

      Attachments

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

        Activity

          People

            agolubev Andrei Golubev
            miikapernu Miika Pernu
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes