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. -
@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.
-
@Risver
What "new data", from where? Do you mean something like over-pasting a selected column's data with other data in theQTreeView
UI? Do you mean updating all rows to change one column's data in the model and/or the SQL database? Programatically or by user interaction? Or what? -
@Risver
What "new data", from where? Do you mean something like over-pasting a selected column's data with other data in theQTreeView
UI? Do you mean updating all rows to change one column's data in the model and/or the SQL database? Programatically or by user interaction? Or what?@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver
What "new data", from where? Do you mean something like over-pasting a selected column's data with other data in theQTreeView
UI? Do you mean updating all rows to change one column's data in the model and/or the SQL database? Programatically or by user interaction? Or what?I mean updating all rows to change one column's data in the model(not in SQL), I would like this to happen programatically.
The passwords in database are encrypted, I want them to be decrypted when I open the application.
-
@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver
What "new data", from where? Do you mean something like over-pasting a selected column's data with other data in theQTreeView
UI? Do you mean updating all rows to change one column's data in the model and/or the SQL database? Programatically or by user interaction? Or what?I mean updating all rows to change one column's data in the model(not in SQL), I would like this to happen programatically.
The passwords in database are encrypted, I want them to be decrypted when I open the application.
-
@Risver
The you must loop over each row, updating the column:for (int row = 0; row < querymodel->rowCount(); row++) querymodel->setData(querymodel->index(row, someColumnNumber), someValue);
Is that what you meant?
@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver
The you must loop over each row, updating the column:for (int row = 0; row < querymodel->rowCount(); row++) querymodel->setData(querymodel->index(row, someColumnNumber), someValue);
Is that what you meant?
Yes, thank you. But it is also changing the data in database.
-
@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver
The you must loop over each row, updating the column:for (int row = 0; row < querymodel->rowCount(); row++) querymodel->setData(querymodel->index(row, someColumnNumber), someValue);
Is that what you meant?
Yes, thank you. But it is also changing the data in database.
-
@Risver
Of course. If you change aQSqlTableModel
's data it will end up updating the database. That's the point of it.You need to think out what you do and do not want to update, when and why.
@JonB
Now i'm usingui->tableView->model()->setData(ui->tableView->model()->index(i, 3), passdecoded);
But it's only work for first row.
for(int i = 0; i < table->rowCount(); i++) { QByteArray pass = ui->tableView->model()->data(ui->tableView->model()->index(i, 3)).toString().toUtf8(); pass = QByteArray::fromBase64(pass); QString passdecoded = decoding(pass); qDebug() << passdecoded; ui->tableView->model()->setData(ui->tableView->model()->index(i, 3), passdecoded); }
Now i see its also changing the data in database...
-
@JonB
Now i'm usingui->tableView->model()->setData(ui->tableView->model()->index(i, 3), passdecoded);
But it's only work for first row.
for(int i = 0; i < table->rowCount(); i++) { QByteArray pass = ui->tableView->model()->data(ui->tableView->model()->index(i, 3)).toString().toUtf8(); pass = QByteArray::fromBase64(pass); QString passdecoded = decoding(pass); qDebug() << passdecoded; ui->tableView->model()->setData(ui->tableView->model()->index(i, 3), passdecoded); }
Now i see its also changing the data in database...
@Risver
Read https://doc.qt.io/qt-5/qsqltablemodel.html#submitAll, https://doc.qt.io/qt-5/qsqltablemodel.html#EditStrategy-enum and https://doc.qt.io/qt-5/qsqltablemodel.html#setEditStrategy, and check what yours currently is. -
@Risver
Read https://doc.qt.io/qt-5/qsqltablemodel.html#submitAll, https://doc.qt.io/qt-5/qsqltablemodel.html#EditStrategy-enum and https://doc.qt.io/qt-5/qsqltablemodel.html#setEditStrategy, and check what yours currently is.@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver
Read https://doc.qt.io/qt-5/qsqltablemodel.html#submitAll, https://doc.qt.io/qt-5/qsqltablemodel.html#EditStrategy-enum and https://doc.qt.io/qt-5/qsqltablemodel.html#setEditStrategy, and check what yours currently is.I'm not sure, before i used setEditStrategy() only the first row was changed, when i used OnFieldChange, all was changed but it was applied to database, when i used OnRowChange and OnManualSubmit only the last row was changed.
-
@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver
Read https://doc.qt.io/qt-5/qsqltablemodel.html#submitAll, https://doc.qt.io/qt-5/qsqltablemodel.html#EditStrategy-enum and https://doc.qt.io/qt-5/qsqltablemodel.html#setEditStrategy, and check what yours currently is.I'm not sure, before i used setEditStrategy() only the first row was changed, when i used OnFieldChange, all was changed but it was applied to database, when i used OnRowChange and OnManualSubmit only the last row was changed.
-
@JonB said in Deleting row from QTableWidget and from Sqlite database:
@Risver This is over to you now.
Thank you for your help, but I already solved the problem myself. Passwords are decrypted when the application is turned on, and encrypted when closed.