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. Custom properties in QML
Forum Updated to NodeBB v4.3 + New Features

Custom properties in QML

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.3k 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.
  • M Offline
    M Offline
    maxpayne
    wrote on last edited by
    #1

    I will appreciate it if someone can give me a hint or two about this problem:

    I have a QML component that receives some data from C++ code. The data is of format QList<QStringList>. From my C++ code, i need to pass this data to QML, process the data in the QML component and based on the number of QStringLists in the QList, i need to create ListViews and set their models to the respective QStringList i.e the number of views = the size of the QList

    How do I declare a property of type QList<QStringList> in my QML code? This is the general idea:

    @//C++ code
    QList<QStringList> data;
    QDeclarativeContext *ctxt = rootContext();
    ctxt->setContextProperty("dataModel", QVariant::fromValue(data));
    setSource(QUrl("qrc:/QML/test/main.qml"));

    //main.qml
    Rectangle {
    id: container
    ......
    ......
    ......
    DateComponent {
    dataModel:
    }
    }

    //DateComponent.qml
    Item{
    id: container
    property dataModel
    //parse dataModel and create required number of List views..
    }

    @

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

      With setContextProperty you can pass a QVariant or a QObject. QVariant can not hold a QList<QStringList>. You may try to put your data in a class derived from QObject. Another solution is to write a custom type as explained in qt4/examples/declarative/cppextensions/referenceexamples/adding

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxpayne
        wrote on last edited by
        #3

        thanks. I've put my data in a class derived from QObject.

        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