Please nominate your Qt Champions for 2021!

Can't expose QStringList to custom component TableView

  • I'm using the custom component TableView with one column and would like to use a QStringList in C++ to manage its elements.

    This example shows how to do this for a ListView :
    That works for me.

    In my main.cpp I've got the following code:
    @ QStringList dataList;
    dataList.append("Item 1");
    dataList.append("Item 2");
    dataList.append("Item 3");
    dataList.append("Item 4");

    context->setContextProperty("myModel", QVariant::fromValue(dataList));@

    In my main.qml I use it like this:


                            HeaderSection {
                                property: "title"
                                caption: "Track"
                                width: 200
                            model: myModel
                            width: 200
                            height: 100
                            itemDelegate: Rectangle {
                                     height: 25
                                     width: 100
                                     Text { text: modelData }

    I get these two errors for every element I'm adding:

    @qrc:/desktop-components/components/TableView.qml:278: TypeError: Result of expression 'root.model.get' [undefined] is not a function.
    qrc:/qml/MyProject/main.qml:239: ReferenceError: Can't find variable: modelData@

    Why can't I use the QStringList.

    The source of Tableview.qml can be found here:

  • I don't know but I am pretty certain the property your headersection should bind to is called "text" and not "title".

Log in to reply