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

qmltc: Provide equivalent of QQmlComponent::createWithInitialProperties()

    XMLWordPrintable

Details

    • 361b60162 (dev), c0982b004 (dev), d1241024e (dev)

    Description

      Currently, qmltc-compiled classes can only be initialized with default values. We need a way to specify initial property values, so that they are available by the time Component.onCompleted is run.

      Some ideas:

      Candidate 1

      A manual completion interface, e.g. an equivalent of QQmlComponent::beginCreate() + QQmlComponent::beginCreate()
       

      Candidate 2

      A constructor or static member function which takes callback to initialize properties before completion, for instance:

      template<typename Fn>
      GeneratedTypeConstructor(QQmlEngine* engine, Fn &&initializer, QObject* parent = nullptr) :
          GeneratedTypeConstructor{parent}
      {
          initializer(*this);
          complete(engine);
      }
      
      // ...
      new GeneratedTypeConstructor(&engine, [&](GeneratedTypeConstructor &o) { /*set properties of o*/ }, parent);
      

      A callback is suggested here instead of QVariantMap to support strong typing.

      Attachments

        Issue Links

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

          Activity

            People

              diseraluca Luca Di Sera
              skoh-qt Sze Howe Koh
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes