what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?
-
wrote on 30 Jan 2019, 11:21 last edited by
in one of my application iam using 'QSqlRelationalTableModel' as the model for listview on QML end
so i have overrided insertRows() ,where before actually inserting new rows iam calling beginInsertRows() function and endInsertRows() after inserting rows.but for some reason listview in QML is ending up with random no of delegates(i.e if i append single row to sqlite table via 'QSqlRelationalTableModel' object ,listview will show same row two times (it looks like i have appended two rows with same data values but i have appended only one ,if i check the physical DB actually only one row is appended!!!)
i guess argument i passed to below functions are not correct !!beginInsertRows(QModelIndex(),totalRows,totalRows); //where totalrows=0 incase firstly there are no rows in table,it will increment by as i append insertRows(totalRows,1,QModelIndex()); endInsertRows();
please tell me what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end .
-
in one of my application iam using 'QSqlRelationalTableModel' as the model for listview on QML end
so i have overrided insertRows() ,where before actually inserting new rows iam calling beginInsertRows() function and endInsertRows() after inserting rows.but for some reason listview in QML is ending up with random no of delegates(i.e if i append single row to sqlite table via 'QSqlRelationalTableModel' object ,listview will show same row two times (it looks like i have appended two rows with same data values but i have appended only one ,if i check the physical DB actually only one row is appended!!!)
i guess argument i passed to below functions are not correct !!beginInsertRows(QModelIndex(),totalRows,totalRows); //where totalrows=0 incase firstly there are no rows in table,it will increment by as i append insertRows(totalRows,1,QModelIndex()); endInsertRows();
please tell me what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end .
wrote on 30 Jan 2019, 11:26 last edited by@divaindie said in what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?:
insertRows(totalRows,1,QModelIndex());
That one will call
begin
/endInsertRows
again (if not actually calling an infinite recursion). Why do you need to subclassQSqlRelationalTableModel
? the default implementation ofinsertRows
should work just fine -
wrote on 30 Jan 2019, 12:33 last edited by
if i have to use "QSqlRelationalTableModel" as a model to listview in QML, i need to generate role names(that i will be generating it in my subclass) . that is the reason i created a derived class of "QSqlRelationalTableModel" !!!
also in QT doc it is mentioned that if we override insertRows() , we must call begin & endInsertRows in our overrided function.
-
if i have to use "QSqlRelationalTableModel" as a model to listview in QML, i need to generate role names(that i will be generating it in my subclass) . that is the reason i created a derived class of "QSqlRelationalTableModel" !!!
also in QT doc it is mentioned that if we override insertRows() , we must call begin & endInsertRows in our overrided function.
wrote on 30 Jan 2019, 12:36 last edited by@divaindie said in what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?:
i need to generate role names(that i will be generating it in my subclass) . that is the reason i created a derived class of "QSqlRelationalTableModel" !!!
Makes sense
@divaindie said in what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?:
also in QT doc it is mentioned that if we override insertRows() , we must call begin & endInsertRows in our overrided function.
Why are you overriding
insertRows
? You don't have to override every single method of the subclass
1/4