Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ASSERT: "first <= rowCount(parent)" in file itemmodels\qabstractitemmodel.cpp with TableView QC1
Forum Updated to NodeBB v4.3 + New Features

ASSERT: "first <= rowCount(parent)" in file itemmodels\qabstractitemmodel.cpp with TableView QC1

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 873 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.
  • C Offline
    C Offline
    chilarai
    wrote on 1 Jun 2021, 05:04 last edited by
    #1

    Hi all,

    I have the following TableView in QML and implemented a normal QSqlQueryModel as the data model. The model in itself runs without error. But, at times when I run it in my TableView, I get ASSERT: "first <= rowCount(parent)" in file itemmodels\qabstractitemmodel.cpp. I did not find any relevant documentation to rectify the same. What could be wrong with the TableView or if somebody can point me to the right documentation?

    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.2
    import QtQuick.Controls.Styles 1.2
    
    
    Rectangle {
        id: win
        width: parent.width
        height: parent.height
        visible: true
    
        Connections{
            target: QueryModel
    
            function onHeaderDataChanged(tableHeaders){
                setHeaders(tableHeaders)
            }
        }
    
        function setHeaders(tableHeaders){
            if(tableHeaders.length > 0){
                roleNames = tableHeaders
    
                for(var i=0; i<roleNames.length; i++){
                    var role  = roleNames[i]
                    var columnString = 'import QtQuick 2.3; import QtQuick.Controls 1.2; TableViewColumn {role: "' + role + '"; title: "' + role + '"; }';
                    newObject[i] = Qt.createQmlObject(columnString, view)
                    view.addColumn(newObject[i])
                }
            }
        }
    
        function clearTable(){
            for(var i=0; i<roleNames.length; i++){
                view.removeColumn(newObject[i])
                delete newObject[i]
    
            }
        }
    
    
        TableView {
            id:view
            width: parent.width
            height: parent.height
            alternatingRowColors: false
            visible: false
            model: QueryModel
    
            style: TableViewStyle {
                headerDelegate: Rectangle {
                    height: textItem.implicitHeight * 1.8
                    width: textItem.implicitWidth
                    color: Constants.themeColor
    
                    Text {
                        id: textItem
                        anchors.fill: parent
                        verticalAlignment: Text.AlignVCenter
                        horizontalAlignment: styleData.textAlignment
                        anchors.leftMargin: 12
                        text: styleData.value
                        elide: Text.ElideRight
                        color: textColor
                        font.bold: true
                        renderType: Text.NativeRendering
    
    
                    }
                }
    
                itemDelegate: Rectangle {
                    color: "white"
    
    
                    Text {
                        id: textItem1
                        anchors.fill: parent
                        verticalAlignment: Text.AlignVCenter
                        text: QueryModel.data(QueryModel.index(styleData.row, styleData.column))
                        horizontalAlignment: styleData.textAlignment
                        anchors.leftMargin: 12
                        elide: Text.ElideRight
                        color: textColor
                        renderType: Text.NativeRendering
    
                    }
                }
            }
        }
    }
    
    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 1 Jun 2021, 09:39 last edited by
      #2

      Looks like a problem with QueryModel. Can you post the code of that class?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chilarai
        wrote on 1 Jun 2021, 10:33 last edited by
        #3

        Thanks @VRonin. You are right. I tried to change the behavior of rowCount() method which was not behaving properly on Qml TableView.

        I have fixed it now.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pchoppa
          wrote on 1 Oct 2021, 03:58 last edited by
          #4

          @chilarai - Could you please let me know what exactly you did to get rid of this assertion?

          I'm having a similar problem with my tree view and struggling for two days. ANy help is greatly appreciated. Thank you!

          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