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.
-
@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.
-
@SGaist
I realize this, but i have no idea how to do it differently. I don't know how to download the passwords from db and send them to the tableView without updating the database.@Risver said in Deleting row from QTableWidget and from Sqlite database:
I don't know how to download the passwords from db and send them to the tableView without updating the database.
I don't know if you wish to discuss this any further, but if you do you would have to explain what this means, and why it has anything to do with the view (rather than the model), plus where updating the database is involved.
When you put passwords into storage (like a database) there are two possible approaches, depending on what you need to do with the passwords:
-
If you need to decrypt them for some purpose (e.g. you have to pass it on in clear-text to something else) you have to use a symmetric (two-way) encryption algorithm, and that is inherently unsafe. Anyone else armed with the decryption algorithm can discover what the original clear-text password was.
-
But if you only to check user input against a previously supplied password, you do not need to decrypt, and you should use an asymmetric (one-way) algorithm. You store the previously-encrypted password and when the user supplies the password to check you only encrypt that as you did when storing, and compare that against what was stored. Either the encrypted versions are the same or they are not. This way end users/hackers cannot discover the saved password by decrypting, because that is not available, they simply have to supply the right password so that it is correct when encrypted only. For example, your SQL password or OS logon password is stored this way.
-