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. Binding a model does not work when I try to use a property with type ListModel
Forum Updated to NodeBB v4.3 + New Features

Binding a model does not work when I try to use a property with type ListModel

Scheduled Pinned Locked Moved QML and Qt Quick
listviewmodelqml
2 Posts 2 Posters 1.1k 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.
  • A Offline
    A Offline
    a.toraby
    wrote on last edited by a.toraby
    #1

    Hi
    I have a model populated from c++ side named: realTimeListModel
    When I write these lines of code it works fine and the data is displayed successfully:

    ListView{
                    width: Screen.desktopAvailableWidth
                    height: Screen.desktopAvailableHeight
                    model: realTimeListModel
                    id: realTimeListViewId
                    delegate: Component {
                        Item {
                            width: Screen.desktopAvailableWidth
                            height: 80
                            Column {
                                Text { text: '<b>Status name:</b> ' + statusId }
                                Text { text: '<b>Value:</b> ' + value }
                                Text { text: '<b>Description:</b> ' +  description}
                            }
                        }
                    }
                }
    

    Since I need to display the same list in several places. I decided to create a reusable list component with the same graphic. So I simply copied the code in another qml file: Here is the content of the StatusList.qml

    import QtQuick 2.4
    import QtQuick.Controls 1.3
    import QtQuick.Controls.Styles 1.2
    import QtQuick.Window 2.2
    import QtQuick.Dialogs 1.2
    Rectangle{
        property ListModel items
        ListView{
            width: Screen.desktopAvailableWidth
            height: Screen.desktopAvailableHeight
            model: items
            delegate: Component {
                Item {
                    width: Screen.desktopAvailableWidth
                    height: 80
                    Column {
                        Text { text: '<b>Status name:</b> ' + statusId }
                        Text { text: '<b>Value:</b> ' + value }
                        Text { text: '<b>Description:</b> ' +  description}
                        }
                   }
              }
         }
    }
    

    The items is the property that is used to bind the model in the main qml:

     StatusList{
                    id: realTimeListView
                    items: realTimeListModel
                }
    

    It does not show anything. and this error occurs:

    Unable to assign StatusModel to QQmlListModel
    

    The StatusModel is the QAbstractListModel that I created in c++ to store the data. Why it can be assigned But it fails when I try to assign it to a loaded component from another file using the declared property "items".
    By the way. If I replace the StatusModel with a simple qml ListModel binding the list through the items property works nice.
    Thanks for any help.

    1 Reply Last reply
    0
    • TobyYiT Offline
      TobyYiT Offline
      TobyYi
      wrote on last edited by
      #2
      • If you can upload your code ,I think it can be solved

      将QtCoding进行到底,做Qt的宠儿
      关注移动互联网,关注手机助手
      开发即时通讯,服务于金融行业
      My github :https:&#x2F;&#x2F;github.com&#x2F;toby20130333

      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