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. Can a QDeclarativeListProperty be accessed directly, instead of as a model?
Forum Updated to NodeBB v4.3 + New Features

Can a QDeclarativeListProperty be accessed directly, instead of as a model?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    ErikZane
    wrote on last edited by
    #1

    I'm trying to use a QDeclarativeListProperty in order to manage a list of parameters, mostly for the purposes of displaying them in a ListView. However, I would also like to be able to directly access the parameters in QML from the QDeclarativeListProperty so that I can display/modify individual parameters on different screens.

    My class is called ParameterClass, for which I've created a QList:

    @
    class SystemData : public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QDeclarativeListProperty<ParameterClass> parameters READ parameters NOTIFY parametersChanged)
    QDeclarativeListProperty<ParameterClass> parameters();

    ...
    
    QList<ParameterClass *> m_parameterList;
    

    }
    @
    I've also registered the ParameterClass class and set up an instance of my SystemData as a property, which I know is necessary.

    @
    m_context->setContextProperty("SystemData", m_pSystemData);
    qmlRegisterType<ParameterClass>();
    @

    Now, what I want to do within QML is something like this:

    @
    Rectangle {
    id: frame
    property variant parameter: SystemData.parameters[5]
    ...
    }
    @

    I'm just not getting it to work: I keep getting back [undefined]. Am I wasting my time, or am I missing something?

    --
    Erik D. Zane
    ezane@harsco.com
    erik.zane@gmail.com

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dasun
      wrote on last edited by
      #2

      I'm not familiar with qt 4.x but I guess you can use "at function":http://harmattan-dev.nokia.com/docs/library/html/qt4/qdeclarativelistproperty.html#AtFunction-typedef directly inside qml as in qt 5.x.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ErikZane
        wrote on last edited by
        #3

        [quote author="dasun" date="1382849565"]I'm not familiar with qt 4.x but I guess you can use "at function":http://harmattan-dev.nokia.com/docs/library/html/qt4/qdeclarativelistproperty.html#AtFunction-typedef directly inside qml as in qt 5.x.[/quote]

        That would work for a QList<QObject*>, but I'm working with a QDeclarativeListProperty.

        I now have this working. I think there was one error that I was facing that had to do with something unrelated to what I was trying to do here, but also I was informed "here":http://stackoverflow.com/questions/19503898/can-a-qdeclarativelistproperty-be-accessed-directly-instead-of-as-a-model that I needed to setup my context properties and registered types before loading my source URL. Once I rearranged my code to make that happen, everything did start to work. I don't know if that's a known issue or bug, and if the same goes for Qt 5.x.

        --
        Erik D. Zane
        ezane@harsco.com
        erik.zane@gmail.com

        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