Deleting row from QTableWidget and from Sqlite database
-
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.
-
@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.
-
@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.
@Risver said in Deleting row from QTableWidget and from Sqlite database:
@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.
Base64 is not encryption. It's just encoding. I will be blunt: your password management is just plain wrong. Passwords shall be encrypted with a real encryption algorithm and they are never decrypted because it's a one way algorithm. If you want to avoid troubles in the future, take your time to properly implement that part.
-
@Risver said in Deleting row from QTableWidget and from Sqlite database:
@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.
Base64 is not encryption. It's just encoding. I will be blunt: your password management is just plain wrong. Passwords shall be encrypted with a real encryption algorithm and they are never decrypted because it's a one way algorithm. If you want to avoid troubles in the future, take your time to properly implement that part.
@SGaist said in Deleting row from QTableWidget and from Sqlite database:
@Risver said in Deleting row from QTableWidget and from Sqlite database:
@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.
Base64 is not encryption. It's just encoding. I will be blunt: your password management is just plain wrong. Passwords shall be encrypted with a real encryption algorithm and they are never decrypted because it's a one way algorithm. If you want to avoid troubles in the future, take your time to properly implement that part.
I'm using "qaesencryption", the passwords are safe.
-
@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.
@Risver said in Deleting row from QTableWidget and from Sqlite database:
Passwords are decrypted when the application is turned on, and encrypted when closed.
This is not safe.