#StackBounty: #python #mysql #pyqt #pyqt4 Error: "Driver not loaded" in PyQt

Bounty: 50

i’m about to connect PyQt5 to MySQL. Unfortunately I get the error’ Driver not loaded’. Python says the driver’s inside:

from PyQt5.QtSql import QSqlDatabase
print(list(map(str, QSqlDatabase.drivers())))

Answer: [‘QSQLITE’, ‘QMYSQL’, ‘QMYSQL3’, ‘QODBC’, ‘QODBC3’, ‘QPSQL’, ‘QPSQL7’]
I use Windows 7 and Qt Designer is installed

here’s my code:

from PyQt5.QtSql import QSqlDatabase, QSqlQuery, QSqlTableModel
from PyQt5.QtWidgets import QTableView, QApplication
import sys
app = QApplication(sys.argv)
db = QSqlDatabase.addDatabase('QMYSQL')
db.setHostName('****')
db.setDatabaseName('****')
db.setUserName('****')
db.setPassword('****')
ok = db.open()
if not ok: print(db.lastError().text())
else: print("connected")
query = QSqlQuery(db);
query.exec_('SELECT * FROM tbl_Customers');

Who has experience with it. Thank you very much


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.