Deleting row from QTableWidget and from Sqlite database
-
@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 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.
-
@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); } }
-
@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();
-
Does your table has a primary key? Otherwise removing will not work.
-
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.
-
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.
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?
-
@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. -
@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.....@JonB said in Deleting row from QTableWidget and from Sqlite database:
qDebug() << querymodel->removeRows(addressId, 1);
Please add
qDebug() << addressId
, we need to make sure what that is, just in case.....It is a variable to store the selected row, for example when i select the first row, it returns 0.
I checked this and its working fine -
@JonB said in Deleting row from QTableWidget and from Sqlite database:
qDebug() << querymodel->removeRows(addressId, 1);
Please add
qDebug() << addressId
, we need to make sure what that is, just in case.....It is a variable to store the selected row, for example when i select the first row, it returns 0.
I checked this and its working fine -
@Risver
OK, so independent of your selectionquerymodel->removeRows(0, 1);
fails to remove the first row? We can then rule out anything to do with the UI or the selection. -
@Risver
OK, so independent of your selectionquerymodel->removeRows(0, 1);
fails to remove the first row? We can then rule out anything to do with the UI or the selection.@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver
OK, so independent of your selectionquerymodel->removeRows(0, 1);
fails to remove the first row? We can then rule out anything to do with the UI or the selection.Do you have something specific in mind ?
-
@Risver
Hang on. DoesQSqlQueryModel
allow any removing it all? It's a query, it won't/shouldn't do anything to the database for sure.[Yep, I'm sure,
QSqlQueryModel
is a read only model, you can't remove rows from it.]If you are wanting to alter the underlying the database table, I think you should be using
QSqlTableModel
instead?I leave this to you, or @Christian-Ehrlicher, now, as I'm done for the week :)
-
@Risver
Hang on. DoesQSqlQueryModel
allow any removing it all? It's a query, it won't/shouldn't do anything to the database for sure.[Yep, I'm sure,
QSqlQueryModel
is a read only model, you can't remove rows from it.]If you are wanting to alter the underlying the database table, I think you should be using
QSqlTableModel
instead?I leave this to you, or @Christian-Ehrlicher, now, as I'm done for the week :)
@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver
Hang on. DoesQSqlQueryModel
allow any removing it all? It's a query, it won't/shouldn't do anything to the database for sure.[Yep, I'm sure,
QSqlQueryModel
is a read only model, you can't remove rows from it.]If you are wanting to alter the underlying the database table, I think you should be using
QSqlTableModel
instead?I leave this to you, or @Christian-Ehrlicher, now, as I'm done for the week :)
Okay, thank You, I will try to use QSqlTableModel.
-
Hi,
Do you mean an entire column ?
-
Yes, select the whole column and then use a loop to parse the selection.