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 ?
-
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 ?
wrote on 3 Oct 2017, 12:22 last edited by@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 ?
-
wrote on 3 Oct 2017, 12:50 last edited by JonB 10 Mar 2017, 12:52
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
-
wrote on 3 Oct 2017, 12:56 last edited by theo_ld 10 Mar 2017, 13:03
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 ?
-
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 ?
-
wrote on 3 Oct 2017, 13:08 last edited by theo_ld 10 Mar 2017, 13:13
@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 -
@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 finishedwrote on 3 Oct 2017, 13:52 last edited by JonB 10 Mar 2017, 13:57@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)? -
wrote on 3 Oct 2017, 13:56 last edited by theo_ld 10 Mar 2017, 13:57
@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 -
@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 :pwrote on 3 Oct 2017, 13:59 last edited by@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... ;-)
-
@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... ;-)
wrote on 3 Oct 2017, 14:07 last edited byThis post is deleted!
11/11