Array of struct to ListView model



  • Hi guys,I have an array of structes,somethnig like this
    @ struct unit{
    string from,
    string to,
    double coeff,
    double degree};@
    how can I pass this array to qml?I want to make that model for my listview



  • You can only expose qobject and certain basic types to qml. You need to wrap your struct in a qobject class.
    For arrays you need to use either a model such as qabstractlistmodel or qqmllistproperty



  • [quote author="t3685" date="1414696300"]You can only expose qobject and certain basic types to qml. You need to wrap your struct in a qobject class.
    For arrays you need to use either a model such as qabstractlistmodel or qqmllistproperty[/quote]
    Only this? Are there any simpler way?



  • As far as I know yes. The abstract list model is easiest and easy in general in my opinion. You only need to reimplement four or so virtual functions, which is quite straightforward and internally you can your array of struts.

    Doesn't get much easier than that


Log in to reply
 

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