Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Set ListElement role from c++

Set ListElement role from c++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 299 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zedroid
    wrote on last edited by
    #1

    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
            }
    

    main.cpp

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

    c++ Val class:

    class Val: public QObject{
        Q_OBJECT
        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_OBJECT
        Q_PROPERTY(Val* value READ value NOTIFY valueChanged)
    }
    
    1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved