-1

I'm new to PyQt and I'm developing an app that was supposed to import data from MySQL database and show it as QSqlTableModel. I'm aware that MySQL drivers are no longer included in PySide6 package, so I tried compiling them myself - using this YouTube guide. Unfortunately it didn't work, so I've also tried precompiled .dlls and they somewhat worked. From not loading anything and huge dependency issues I've come to simple load issue. Unfortunately I don't know how to resolve it.

Here's what QT_DEBUG_PLUGINS = 1 (and what I think its most relevant part is):

qt.core.library: "C:/Users/aroma/AppData/Roaming/Python/Python39/site-packages/PySide6/plugins/sqldrivers/qsqlmysql.dll" cannot load: Cannot load library C:\Users\aroma\AppData\Roaming\Python\Python39\site-packages\PySide6\plugins\sqldrivers\qsqlmysql.dll: Nie można odnaleźć określonej procedury.
qt.core.plugin.loader: QLibraryPrivate::loadPlugin failed on "C:/Users/aroma/AppData/Roaming/Python/Python39/site-packages/PySide6/plugins/sqldrivers/qsqlmysql.dll" : "Cannot load library C:\\Users\\aroma\\AppData\\Roaming\\Python\\Python39\\site-packages\\PySide6\\plugins\\sqldrivers\\qsqlmysql.dll: Nie można odnaleźć określonej procedury."
QSqlDatabase: QMYSQL driver not loaded

If that's relevant, my code is:

import sys
from pathlib import Path
from PySide6.QtCore import Qt, QUrl, QAbstractTableModel, QModelIndex, QObject, Slot, Signal
from PySide6.QtWidgets import QApplication, QTableView
from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType
from PySide6.QtGui import QStandardItemModel, QStandardItem
from PySide6.QtSql import QSqlDatabase
import mysql.connector

db = QSqlDatabase.addDatabase("QMYSQL")
db.setHostName("localhost")
db.setDatabaseName("database")
db.setUserName("root")
db.setPassword("password")

if db.open():
    print("It lives!")


if __name__ == "__main__":
    app = QApplication(sys.argv)
    engine = QQmlApplicationEngine()
    qml_file = Path(__file__).resolve().parent / "qml/main.qml"
    engine.load(qml_file)
    sys.exit(app.exec())

What I tried.

I tried changing %PATH% to "C:/Users/aroma/AppData/Roaming/Python/Python39/site-packages/PySide6/plugins/sqldrivers", but it didn't work.

I also tried adding libmysql.dll to the folder containing my main.py file, but it didn't work too.

Finally, I tried adding path to folder_containing_my_py_file/plugins as %QT_PLUGIN_PATH%, but it didn't work as well. The error is the same, although in new directory.

qt.core.library: "C:/Users/aroma/Desktop/programy/Qt-Studio/program-magazynowy/Qt-program/magazyn-nowy/plugins/sqldrivers/qsqlmysql.dll" cannot load: Cannot load library C:\Users\aroma\Desktop\programy\Qt-Studio\program-magazynowy\Qt-program\magazyn-nowy\plugins\sqldrivers\qsqlmysql.dll: Nie można odnaleźć określonej procedury.
qt.core.plugin.loader: QLibraryPrivate::loadPlugin failed on "C:/Users/aroma/Desktop/programy/Qt-Studio/program-magazynowy/Qt-program/magazyn-nowy/plugins/sqldrivers/qsqlmysql.dll" : "Cannot load library C:\\Users\\aroma\\Desktop\\programy\\Qt-Studio\\program-magazynowy\\Qt-program\\magazyn-nowy\\plugins\\sqldrivers\\qsqlmysql.dll: Nie można odnaleźć określonej procedury."

Thanks for your help!

Adrian
  • 1
  • 2
  • Try to do *all* the `db` stuff **after** creating the QApplication instance, not before. – musicamante Aug 21 '23 at 22:43
  • Thanks for your answer! It didn't work though, it produces the same error. – Adrian Aug 22 '23 at 00:15
  • It's unclear. Post a [mre] with debugging details. Is your result coming from using an arbitrary downloaded ```qsqlmysql.dll``` file from an unknown source? Anyway, that Polish error message seems to be corresponding to the ```ERROR_PROC_NOT_FOUND```, which means the Qt cannot load that DLL file. See [this answer](https://stackoverflow.com/a/37168974/1186624). – relent95 Aug 23 '23 at 02:10

0 Answers0