How to get ListModel from QML to a C++ class?



  • Hello,

    Just as my title says is there a way to send a ListModel filled in QML to a C++ class.

    I've been using some C++ bindings and Q_PROPERTY to try to achieve this but with no success.

    Hopefully there is some example on how to do this.

    Thanks in advance :O



  • It is a no no, you need to create your model in C++ and keep it there and only interface it to QML. You could pull the data one element at a time, but the proper way to go is use a C++ model to begin with.



  • There is nothing inherently wrong with it.
    You should be able to create a property that takes a QObject* and dynamic_cast it to QAbstractItemModel*.

    That is the trick when doing the other way around. When you create a model from C++ to use in QML, your function/method should return QObject*, it will not work with any of the QAbstract*Model classes that I have tried.



  • [quote author="thiagocorrea" date="1363832522"]There is nothing inherently wrong with it.
    You should be able to create a property that takes a QObject* and dynamic_cast it to QAbstractItemModel*.

    That is the trick when doing the other way around. When you create a model from C++ to use in QML, your function/method should return QObject*, it will not work with any of the QAbstract*Model classes that I have tried.[/quote]

    Ok I think I will try your approach. Ill keep posting my results.


Log in to reply
 

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