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. Can't expose QStringList to custom component TableView
Qt 6.11 is out! See what's new in the release blog

Can't expose QStringList to custom component TableView

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 3.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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 : http://doc.trolltech.com/4.7-snapshot/declarative-modelviews-stringlistmodel.html
    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:

    @
    TableView{

                            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:
    http://qt.gitorious.org/qt-components/desktop/blobs/master/components/TableView.qml

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

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

      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