pyQt5 - QTableWidget get refreshed
-
I have a python script that loads data from a table of mySQL db into a QTableWidget. in such QTableWidget the user can push a button to delete a row in the MySQL table. The code works fine but I'm not able to get the QtableWidget refreshed after the delete button has been pressed and the corresponding record has been deleted as well from the db table.
-
I have a python script that loads data from a table of mySQL db into a QTableWidget. in such QTableWidget the user can push a button to delete a row in the MySQL table. The code works fine but I'm not able to get the QtableWidget refreshed after the delete button has been pressed and the corresponding record has been deleted as well from the db table.
@Achab61 QTableWidget is not the right tool for your use case.
You should rather take a look at https://doc.qt.io/qt-5/model-view-programming.html -
I'm pretty new in Python and PyQt5 and most likely you're right.
However on the web (especially on YouTube) there are lot of tutorials where QTableWidget is always used to manage data from/to SQL db and I guessed the QTableWidget refreshing was a common need (but maybe not...). Which tool should be used instead of QTableWidget ? -
Hi,
Usually QSqlTableModel with a QTableView.
As for your current problem, it's your job to remove the data from your QTableWidget since it has in fact no connection to the database.
-
OK. I tried tu use QSqlTableModel but I get the error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7Checking some posts I came to the conclusion I should build the MYSQL driver, so I tried to run
/Users/MyUser/Qt/QtDesignStudio/qt5_design_studio_reduced_version/bin/qmake -- MYSQL_PREFIX=/usr/local
but it seems that the parameter MYSQL_PREFIX.... is not recognized as I'm still getting:
Usage: /Users/MyUser/Qt/QtDesignStudio/qt5_design_studio_reduced_version/bin/qmake [mode] [options] [files]
I run the qmake command from:
/Users/MyUser/Qt/QtDesignStudio/qt5_design_studio_reduced_version/plugins/sqldrivers)
I use Mac OS.X Monterey 12.2
-
Do you have the Qt sources matching the Qt version you are using ?
-
You are trying to build the MySQL backend, this require to have the Qt source code.