Get List Properties from QML in C++



  • Hi Guys. I m developing converter plugin for QML, and the task is to catch list properties from QML file.
    I have QML components in my plugin.

    qmlRegisterType<Converter>(uri, 1, 0, "Converter");
        qmlRegisterType<Unit>(uri, 1, 0, "Unit");
    

    What I want:
    QML

    Converter {
    Unit {
    name: "g"
    coefficient: 1
    }
    
    Unit {
    name: "Kg"
    coefficient: 1000
    }
    
    }
    

    I want to be able to access list of Unit objects from C++.
    At the moment I have the property in Converter Class:

    Q_PROPERTY(QQmlListProperty<Unit> units READ units NOTIFY unitsChanged)
    

    But I completely fail i tries to get values of QQmlListProperty<Unit> in C++.
    What is the right approach to get these list properties from QML to C++?
    Please help if you know solution. I am struggling with this task for 2 days.


  • Moderators

    Hi @Kofr
    Check out this example especially this file. There you can use findChild instead to find Converter and then get the data in the same way.



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