Solved Deleting row from QTableWidget and from Sqlite database
-
@Risver said in Deleting row from QTableWidget and from Sqlite database:
I just installed it a while time ago.
Before you spend any more time on this. Qt5 is already up to 5.15, unless you have some deep reason for wanting 5.0 I would uninstall and get such an up-to-date version.
-
@JonB
I can just upgrade Qt to v6 and see if it works -
@Risver
You can indeed, though my personal preference would be to take the latest Qt5.x release. I still see too many issues with Qt6, not to mention that I think they still have not ported all modules, depends what bits you will be using.However, my learned colleagues may disagree and advise you to go for Qt6, i don't know....
-
@JonB
I'm installing Qt 6 for now, i will check if everything works. If it won't i will install Qt 5.15Okay, I configured the project in the new Qt and i still have the same error.
-
@Risver said in Deleting row from QTableWidget and from Sqlite database:
I configured the project in the new Qt and i still have the same error.
And you are sure you're building with Qt6 now?
And did you do a complete rebuild? -
@jsulm said in Deleting row from QTableWidget and from Sqlite database:
@Risver said in Deleting row from QTableWidget and from Sqlite database:
I configured the project in the new Qt and i still have the same error.
And you are sure you're building with Qt6 now?
And did you do a complete rebuild?Yes i'm sure i building with Qt6,
but i'm not sure how can i complete rebuild the project.
found this. Still have error -
@Risver said in Deleting row from QTableWidget and from Sqlite database:
The QT version is 5.0.2
I'm guessing 5.0.2 is/was your QtCreator version (the IDE) not the version of Qt. Look at the 'Kit' you are using, it will say what version of Qt you are using.
-
-
@mchinand
Yes you're right. -
@Christian-Ehrlicher said in Deleting row from QTableWidget and from Sqlite database:
querymodel->removeRow(addressId, 1);
model->removeRows(row, 1);
Thank You Christian, now i have no errors, but it is not removing.
-
@Risver
@Christian-Ehrlicher's comment above is why your linequerymodel->removeRow(addressId, 1);
is generating an error. Look at the two different methods he has given you links to. -
@Risver said in Deleting row from QTableWidget and from Sqlite database:
Thank You Christian, now i have no errors, but it is not removing.
Start by showing us your new line, because we don't know which of the two methods you changed to using and what parameters you gave it.
-
@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver said in Deleting row from QTableWidget and from Sqlite database:
Thank You Christian, now i have no errors, but it is not removing.
Start by showing us your new line, because we don't know which of the two methods you changed to using and what parameters you gave it.
i've changed only this one:
void MainWindow::on_remove_clicked() { if (ui->tableView->selectionModel()->hasSelection()) { int addressId = ui->tableView->selectionModel()->currentIndex().row(); querymodel->removeRows(addressId, 1); } }
-
qDebug() << querymodel->rowCount(); qDebug() << querymodel->removeRows(addressId, 1); qDebug() << querymodel->rowCount();
-
@JonB said in Deleting row from QTableWidget and from Sqlite database:
qDebug() << querymodel->rowCount(); qDebug() << querymodel->removeRows(addressId, 1); qDebug() << querymodel->rowCount();
The rowCount is always 3 and the removeRows is false.
-
Does your table has a primary key? Otherwise removing will not work.
-
@Christian-Ehrlicher said in Deleting row from QTableWidget and from Sqlite database:
Does your table has a primary key? Otherwise removing will not work.
Yes, it has.
-
@Christian-Ehrlicher said in Deleting row from QTableWidget and from Sqlite database:
Does your table has a primary key? Otherwise removing will not work.
That's very interesting. I assume we're talking about a SQL table model here? I looked through the docs (briefly) but did not see any mention of this requirement, is it documented?
-
@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Christian-Ehrlicher said in Deleting row from QTableWidget and from Sqlite database:
Does your table has a primary key? Otherwise removing will not work.
That's very interesting. I assume we're talking about a SQL table model here? I looked through the docs (briefly) but did not see any mention of this requirement, is it documented?
That is how my SQL Table looks. -
qDebug() << querymodel->removeRows(addressId, 1);
Please add
qDebug() << addressId
, we need to make sure what that is, just in case.....