I wanna make a MySQL database mapping to QTableView but i got this error: QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
My code is:
from mysql.connector import connect, Error
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtSql import QSqlDatabase, QSqlTableModel
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableView
class Ui_self(QMainWindow):
connection = connect(host="",
user='',
password='',
database="",
charset='utf8')
def __init__(self):
super().__init__()
self.setWindowTitle("MySQL Table View")
self.resize(800, 600)
db = QSqlDatabase.addDatabase("QMYSQL")
db.setHostName("")
db.setDatabaseName("")
db.setUserName('')
db.setPassword('')
db.open()
self.setupUi()
self.show()
def setupUi(self):
self.setObjectName("MainWindow")
self.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.model = QSqlTableModel()
self.model.setTable('students')
self.model.setEditStrategy(QSqlTableModel.OnFieldChange)
self.model.select()
self.tableView = QtWidgets.QTableView(self.centralwidget)
self.tableView.setGeometry(QtCore.QRect(0, 0, 801, 561))
self.tableView.setObjectName("tableView")
self.tableView.setModel(self.model)
self.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(self)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
self.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(self)
self.statusbar.setObjectName("statusbar")
self.setStatusBar(self.statusbar)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate("MainWindow", "MainWindow"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ui = Ui_self()
sys.exit(app.exec_())
I have already tried to move qsqlmysql.dll and libmysql.dll in the needs paths by guides but it doesn't helps me
Python 3.9.13 64-bit Windows 10 PyQt ver. 5.15.4