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

qmltc: Provide equivalent of QQmlComponent::createWithInitialProperties()

XMLWordPrintable

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

      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.

        For Gerrit Dashboard: QTBUG-120700
        # Subject Branch Project Status CR V

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes