Solved Removing rows from TableModel
-
Hi and welcome to devnet,
Just to be sure I understand your question correctly, are you asking us to review your code and explain it to you ?
-
@SGaist I said this code was coming from Qt Address Book Example. I've tried it, but I'd like to change some features.
By the way, i'm not sure to understand how the TableModel works. I tried to clear it buttable->removeRows(0, table->rowCount(QModelIndex()));
doesn't work. So yes, can you clarify me this example ?
-
table->removeRows(0, table->rowCount(QModelIndex()));
doesn't work. So yes, can you clarify me this example ?
What does "doesn't work" mean? Compile error? Runtime error? Not the behaviour you expected? ...
- What is your
table->editStrategy()
? Docs state that onlyOnManualSubmit
allows mutliple-row deletion. And then you'll need asubmitAll()
. - Check the return result of your
table->removeRows()
, andlastError()
if that'sfalse
. - I think
table->clear()
is a quick way of deleting all rows, though that may not affect what you are wanting to learn about.
- What is your
-
I run through a Runtime Error ! I'm trying to fix it with your advice ! I believe the
table->clear()
method doesn't exist in TableMethod btw ;) Can you use
table->removeRows()
it if the table is empty ?
-
So tell us the runtime error! And/or check the return result +
lastError()
!clear
method: what is yourTableModel
derived from? -
@JNBarchan
My
TableModel
comes fromQAbstractTableModel
.
lastError() works only for SQL Databases right ? Which object is it stored in ?
Can't check the return of the function because I get a runtime error.Here is the console output
Debugging starts
ASSERT: "last >= first" in file itemmodels\qabstractitemmodel.cpp, line 2743
Debugging has finished -
@theo_ld
Yeah, I had assumedQSqlTableModel
....ASSERT: "last >= first" in file itemmodels\qabstractitemmodel.cpp, line 2743
I would guess this is telling you that your start row number + number of rows >= last row in table.
So: look at value of
table->rowCount(QModelIndex())
. Is it 0? In which case, if there are 0 rows, no, you cannot delete any rows from an empty table, even if you specify a count of 0 rows to delete. At a guess!P.S.
Also,QAbstractTableModel
requires you to subclass (TableModel
), and unless that has implementedremoveRows()
is does nothing? You sure the example which did work did not useremoveRow()
(note the spelling)? -
@JNBarchan You might be right, so I added a condition and it doesn't runtime anymore.
Although, my user isn't visible at all in the graphical interface -_-.
Trying to fix this problem now :p -
@theo_ld said in Removing rows from TableModel:
@JNBarchan You might be right, so I added a condition and it doesn't runtime anymore.
In that case, I'd suggest I was right... ;-)
-
This post is deleted!