QSqlDatabase Driver not loaded
-
wrote on 4 Aug 2018, 15:44 last edited by A Former User 8 Apr 2018, 15:46
Hello, I have a problem while connecting to a database via QtSql. This is a fragment of my code:
QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("SQLFileDatabase"); db.setHostName(host); db.setDatabaseName(nazwa); db.setUserName(login); db.setPassword(haslo); bool ok = db.open();
This is the error I get: pastebin. I have tried moving .lib files and sqldrivers to the .exe directory but it does not help (as you can see in the log).
I am using 32-bit QtCreator and Visual Studio 2017. Thanks for help. -
Hi and welcome to devnet,
Unless you wrote your own driver,
SQLFileDatabase
doesn't exist. It'sQSQLITE
if you are thinking about using a SQLite database. -
wrote on 5 Aug 2018, 09:06 last edited by A Former User 8 May 2018, 09:26
I replaced SQLFileDatabase with QMYSQL and now I get this error:
Cannot load library C:\Qt\5.11.1\msvc2017_64\plugins\sqldrivers\qsqlmysqld.dll: Unknown error 0x000000c1. QLibraryPrivate::loadPlugin failed on "C:/Qt/5.11.1/msvc2017_64/plugins/sqldrivers/qsqlmysqld.dll" : "Cannot load library C:\\Qt\\5.11.1\\msvc2017_64\\plugins\\sqldrivers\\qsqlmysqld.dll: Unknown error 0x000000c1." QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
It works only for QSQLITE.
-
Did you install the needed dependencies ?
If you set the
QT_DEBUG_PLUGINS
environment variable to 1 in the Run part of the Project panel, you will see why the plugin is not loaded. -
wrote on 5 Aug 2018, 22:17 last edited by
This is the log with enabled variable: pastebin. The qsqlmysqld.dll file exists but it does not work (log from previous post). What are the dependencies?
-
wrote on 6 Aug 2018, 04:18 last edited by
Hi is there any difference if you put libmysqld.dll in the same directory as your .exe file?
-
wrote on 6 Aug 2018, 07:10 last edited by
I already have it in the same directory. However, I don't know it if works. It seems that it isn't detected by the program:
QFactoryLoader::QFactoryLoader() looking at "C:/Qt/5.11.1/msvc2017_64/plugins/sqldrivers/libmysqld.dll" "Failed to extract plugin meta data from 'C:/Qt/5.11.1/msvc2017_64/plugins/sqldrivers/libmysqld.dll'" not a plugin
-
As @hskoglund wrote: in the same folder as your application executable, not in the folder of the plugin.
-
wrote on 6 Aug 2018, 07:56 last edited by A Former User 8 Jun 2018, 08:45
-
wrote on 6 Aug 2018, 10:43 last edited by hskoglund 8 Jun 2018, 10:49
Hmm that error 0x000000c1 could mean your 64-bit MySql is not installed 100%.
If you compile in Release mode instead of Debug, you get that same error 0x000000c1?
Edit: also check that you indeed installed the 64-bit version of MySql and not the 32-bit version, easiest way to check:
mysql.exe --V
-
wrote on 6 Aug 2018, 11:42 last edited by A Former User 8 Jun 2018, 11:45
I had 64-bit MySql Server and 32-bit C Connector so I replaced it with 64-bit C++ Conector. I have tried compiling in the Release mode with no success. Should I reinstall the Qt libraries?
Cannot load library C:\Qt\5.11.1\msvc2017_64\plugins\sqldrivers\qsqlmysql.dll
I think this may be the problem - file is in the directory but is not recognized by the program.
-
wrote on 6 Aug 2018, 12:07 last edited by
I think the qsqlmysql.dll file is ok, but since it's depending on libmysql.dll being present in the same directory as your Qt .exe file, if that libmysql.dll is 32-bit, then you could have an error anyway.
-
wrote on 6 Aug 2018, 12:32 last edited by A Former User 8 Jun 2018, 12:34
Can I download it (64 bit, Qt 5.11.1) without reinstalling the whole Qt?
-
wrote on 6 Aug 2018, 12:41 last edited by
I think you can do it by downloading the offline installer (never tried it) but easiest is most likely just to start MaintenanceTool.exe, remove the 5.11.1 MSVC2017 64-bit component and then selecting/installing it again.
-
wrote on 6 Aug 2018, 16:49 last edited by A Former User 8 Jun 2018, 16:53
I have reinstalled the Qt libraries and replaced all the files in the exe directory with the newer version, and it works now. This is what I have in the folder: exe file, libmysql.dll, Qt5Core.dll and Qt5Sql.dll (in release mode).
Thank you for help!
1/15