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



  • 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.



    • If you can upload your code ,I think it can be solved

Log in to reply
 

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