ASSERT: "first <= rowCount(parent)" in file itemmodels\qabstractitemmodel.cpp with TableView QC1
-
wrote on 1 Jun 2021, 05:04 last edited by
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 } } } } }
-
wrote on 1 Jun 2021, 09:39 last edited by
Looks like a problem with
QueryModel
. Can you post the code of that class? -
wrote on 1 Jun 2021, 10:33 last edited by
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.