Searching for something like QQmlListProperty<QQmlComponent>



  • Currently I use a QQmlListProperty<QObject> as DefaultProperty in my C++ class Foo and my QML looks like this:

    Foo {
        Bar {}
        Bar {}
        Bar {}
    }
    

    So nothing really exciting. However, I only need a few of these elements instantiated at the same time (and I already know which ones on the C++ side). My first idea was to use a QmlListProperty<QQQmlComponent>. That would be easy, but unfortunately it does not work.

    I can't change the QML code. But I want to control the instantiation of the elements on the C++ side. As if Bar would be implicitly assigned to a QQmlComponent in the above QML code. Hence the idea with the QQmlListProperty<QQmlComponent>, which unfortunately does not work.

    Does anyone have any ideas on how I could achieve this? Is there any (private) API that could help?

    Thank you in advance
    Stefan



  • Have you found a solution for your issue yet? I'm facing the same question.

    Cheers!


  • Moderators

    @DuBu
    i think there is no workaround yet other than wrapping all child items:

    Foo {
        Component { Bar {} }
        Component { Bar {} }
        Component { Bar {} }
    }
    

    But maybe this is indeed worth a feature request via the bugtracker.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.