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. Array of struct to ListView model
Forum Updated to NodeBB v4.3 + New Features

Array of struct to ListView model

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.8k 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.
  • V Offline
    V Offline
    Vardan95
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vardan95
        wrote on last edited by
        #3

        [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?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          t3685
          wrote on last edited by
          #4

          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

          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