Important: Please read the Qt Code of Conduct -

Set ListElement role from c++

  • Hello!
    Is it possible to set in the ListElement role from the c++ context property?
    In the way like below I have TypeError:
    qml part:

    ListModel {
            id: pictureModel
            ListElement {
                  title: "name"
                  src: "someqml.qml"
                  something: devicemodel.value


    DeviceData devicemodel;
    engine.rootContext()->setContextProperty(QStringLiteral("devicemodel"), &devicemodel);

    c++ Val class:

    class Val: public QObject{
        Q_PROPERTY(unsigned int curValue READ curValue WRITE writeCurValue  NOTIFY curValueChanged)
        Q_PROPERTY(unsigned int maxValue READ maxValue)
        Q_PROPERTY(unsigned int minValue READ minValue)

    Devicedata class

    class DeviceData : public QObject {
        Q_PROPERTY(Val* value READ value NOTIFY valueChanged)

  • Values for roles at ListElement must be a simple constants: strings, numbers and boolean values. In your example value property is pointer.

Log in to reply