Dzień dobry. Pracuję aktualnie nad aplikacją, która ma współpracować z baza danych MySQL. Zainstalowałem XAMPP oraz utworzyłem bazę danych MySQL. Przy próbie nawiązania połączenia z bazą wyskoczył mi błąd dotyczący sterownika QMYSQL:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
Po przeszukaniu sieci zauważyłem, że jest to dość znany błąd w przypadku Qt Creator. Znalazłem dużo rozwiązań, czy to polegających na dodaniu kilku plików, czy na ręcznym buildzie sterownika. Niestety żadne mi nie pomogło. Czego już próbowałem:
-
Próbowałem ręcznie pobrać oraz dodać pliki libmysql.dll oraz libmysqld.dll do folderu debug: P:\Repositories\build-ATLAS-Desktop_Qt_6_1_3_MinGW_64_bit-Debug\debug
Nie pomogło.
-
Próbowałem skopiować z folderu XAMPP pliki libmysql.dll oraz libmysqld.dll i wkleić do D:\Qt\6.1.3\mingw81_64\bin
Nie pomogło.
-
Próbowałem dodać bibliotekę przez Qt Creator :
win32: LIBS += -L'D:/Program Files/MySQL/MySQL Connector C 6.1/lib/' -llibmysql
INCLUDEPATH += 'D:/Program Files/MySQL/MySQL Connector C 6.1/include'
DEPENDPATH += 'D:/Program Files/MySQL/MySQL Connector C 6.1/include'
Niestety to również nic nie dało.
-
W końcu zdecydowałem się zrobić build sterownika wg tego poradnika: https://doc.qt.io/qt-5/sql-driver.html#qmysql
Zainstalowałem MySQL Connector C 6.1.11, sprawdziłem czy są wszystkie pliki i następnie uruchomiłem Qt 6.1.3 (MinGW 8.1.0 64-bit).
Podałem lokalizacje sqldrivers tj.: cd D:\Qt\6.1.3\Src\qtbase\src\plugins\sqldrivers
Kolejną rzeczą był qmake: qmake -- MYSQL_INCDIR="D:\Program Files\MySQL\MySQL Connector C 6.1\include" D:\Program Files\MySQL\MySQL Connector C 6.1\lib"
Przy próbie wpisania komendy mingw32-make pojawił się błąd:
mingw32-make: *** No targets specified and no makefile found. Stop.
Poniżej cały kod z cmd:
Setting up environment for Qt usage...
D:\Qt\6.1.3\mingw81_64>cd D:\Qt\6.1.3\Src\qtbase\src\plugins\sqldrivers
D:\Qt\6.1.3\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="D:\Program Files\MySQL\MySQL Connector C 6.1\include" D:\Program Files\MySQL\MySQL Connector C 6.1\lib"
Usage: qmake [mode] [options] [files]
QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project
Mode:
-project Put qmake into project file generation mode
In this mode qmake interprets [files] as files to
be added to the .pro file. By default, all files with
known source extensions are added.
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
-makefile Put qmake into makefile generation mode (default)
In this mode qmake interprets files as project files to
be processed, if skipped qmake will try to find a project
file in your current working directory
Warnings Options:
-Wnone Turn off all warnings; specific ones may be re-enabled by
later -W options
-Wall Turn on all warnings
-Wparser Turn on parser warnings
-Wlogic Turn on logic warnings (on by default)
-Wdeprecated Turn on deprecation warnings (on by default)
Options:
* You can place any variable assignment in options and it will be *
* processed as if it was in [files]. These assignments will be *
* processed before [files] by default. *
-o file Write output to file
-d Increase debug level
-t templ Overrides TEMPLATE as templ
-tp prefix Overrides TEMPLATE so that prefix is prefixed into the value
-help This help
-v Version information
-early All subsequent variable assignments will be
parsed right before default_pre.prf
-before All subsequent variable assignments will be
parsed right before [files] (the default)
-after All subsequent variable assignments will be
parsed after [files]
-late All subsequent variable assignments will be
parsed right after default_post.prf
-norecursive Don't do a recursive search
-recursive Do a recursive search
-set <prop> <value> Set persistent property
-unset <prop> Unset persistent property
-query <prop> Query persistent property. Show all if <prop> is empty.
-qtconf file Use file instead of looking for qt6.conf, then qt.conf
-cache file Use file as cache [makefile mode only]
-spec spec Use spec as QMAKESPEC [makefile mode only]
-nocache Don't use a cache file [makefile mode only]
-nodepend Don't generate dependencies [makefile mode only]
-nomoc Don't generate moc targets [makefile mode only]
-nopwd Don't look for files in pwd [project mode only]
D:\Qt\6.1.3\Src\qtbase\src\plugins\sqldrivers>mingw32-make
mingw32-make: *** No targets specified and no makefile found. Stop.
D:\Qt\6.1.3\Src\qtbase\src\plugins\sqldrivers>
Próbowałem również wykorzystać Mariadb Connector C 3.1.5 ale bez efektów.
Wrzucam również informację o wersji poszczególnych programów:
Qt Creator 5.0.1 Community
Qt 6.1.3 (MinGW 8.1.0 64-bit)
Qt 6.1.3 (MSVC 2019 64-bit)
XAMPP Control Panel v3.3.0
MySQL Connector C 6.1
MySQL Server 5.5
Nie będę ukrywał, że jeśli chodzi o dodawanie/wgrywanie zewnętrznych bibliotek/plików do Qt Creator jest to dla mnie (nadal) czarna magia. Ostatnio w podobny sposób męczyłem się z Popplerem i w końcu odpuściłem. Mam nadzieję , że tym razem będzie inaczej.
Nie mam zielonego pojęcia jak wgrać ten sterownik do Qt Creator, żeby wszystko działało. Jeżeli ktoś ma jakiś pomysł lub chociaż wskazówkę będę bardzo wdzięczny.
Z góry dziękuję i życzę miłego dnia.