Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!

Forums

OverviewFelgo 2 Support (Qt 5) › Add C++ model (QAbstractListModel) into ListPage with delegated SimpleRow

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #11783

    Sascha

    Hello,

    is it possible to add a derived c++ QAbstractListModel model to a ListPage with delegated SimpleRow ?
    I implemented such a class as singleton and registered it in the main.cpp file via qmlRegisterSingletonType(..).
    In QML I set the ListPage model to the registered singleton model and delegate to SimpleRow. With this constellation
    I receive a “ReferenceError: modelData is not defined” error. But when I change the SimpleRow with a Rectangle element,
    my c++ model works.

     

    Here is some Code:

    main.cpp

    ...
    qmlRegisterSingletonType<SetListModel>("NoNameApp", 1, 0, "SetListModel", SetListModel::getInstance);
    ...
    

     

    ListPage.qml (with SimpleRow)

    import QtQuick 2.4
    import Felgo 3.0
    import NoNameApp 1.0
    
    ListPage {
        id: _set_listpage
        title: qsTr("Test")
        emptyText.text: qsTr("No data available")
    
        delegate: SimpleRow{
            showDisclosure: false
            image.radius: image.height
            image.fillMode: Image.PreserveAspectCrop
            autoSizeImage: true
            imageMaxSize: dp(48)
            detailTextItem.maximumLineCount: 2
            detailTextItem.elide: Text.ElideRight
            detailTextItem.text: model ? ""+model.birthdate + "\n" + ""+model.additionText : ""
            imageSource: model ? model.imageSmall : ""
            textItem.font.pixelSize: sp(16)
            onSelected: {
                navigationStack.popAllAndPush(_set_detail_page, {
                                                setName: model.text,
                                                addition: model.additionText,
                                                imageurl: model.imageBig
                                              })
            }
        }
    
        Component {
            id: _set_detail_page
            SetDetailPage {}
        }
    
        model: SetListModel
    }

    ListPage.qml (with Rectangle)

    import QtQuick 2.4
    import Felgo 3.0
    import NoNameApp 1.0
    
    ListPage {
        id: _set_listpage
        title: qsTr("Test")
        emptyText.text: qsTr("No data available")
    
        delegate: Rectangle{
            width: parent.width
            height: 100
            color: "red"
            Text{
                text: model.id+":"+model.text
            }
        }
    
        Component {
            id: _set_detail_page
            SetDetailPage {}
        }
    
        model: SetListModel
    }

    Best regards

    Sascha

     

    #11784

    Günther
    Felgo Team

    Hi Sascha!

    We designed the SimpleRow type for easy usage with models described as arrays. This turned out to be a problem when using ListModel based types together with the SimpleRow.

    We already fixed this error for the next update. Until then, it should work to add a dummy property “modelData” to your ListModel to get rid of the error.

        ListModel {
          id: listModel
          ListElement { title: "Title"; description: "description"; modelData: "dummy"  }
        }
    
        ListPage {
            title: qsTr("Test")
            model: listModel
            delegate: SimpleRow{
                textItem.text: title
                detailTextItem.text: description
            }
        }

    Hope this also works for your C++ model in the same way!

    Best,
    Günther

     

    #11791

    Sascha

    Hello Günther,

     

    thanks for your help. With a “modelData” dummy in my model it works now.

    Best regards

    Sascha

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.