PDA

View Full Version : MySql and QtPlugin


darksaga
13th May 2007, 18:44
Hello,

Today i've tried to use my mysql db, instead of the sqlite db i used so far.

When i tried to connect to the new db, i came across the QSqlDatabase: QMYSQL driver not loaded error.

To create the missing mysql driver i used following instruction:


1.
cd %QTDIR%\src\plugins\sqldrivers\mysql
qmake -o Makefile "INCLUDEPATH+=C:\MYSQL\INCLUDE" "LIBS+=C:\MYSQL\LIB\OPT\LIBMYSQL.LIB" mysql.pro
nmake
2.
Copy the libmysql.dll file from the MySQL installation's bin directory to a directory in %PATH% (e.g. %QTDIR%/bin). (--> copied to it to C:\Program Files\qt4\bin)


everything worked fine so far, next i insertet

#include <QtPlugin>
Q_IMPORT_PLUGIN(qsqlmysql)

in my code and

QTPLUGIN += qsqlmysql

in my *.pro file, as described here: http://doc.trolltech.com/4.1/plugins-howto.html

while i try to compile the project i get the following errormessage: undefined reference to `qt_plugin_instance_qsqlmysql()

I know adding LIBS += ???.file could help but what files or directories do i have to add ??? Tired already lots of files without results.

Hope someone knows a solution... ;)

PS: using QT::4:2:2 and Visual Studio 2003

patrik08
13th May 2007, 22:58
Hello,

Today i've tried to use my mysql db, instead of the sqlite db i used so far.
PS: using QT::4:2:2 and Visual Studio 2003


can you see the mysql driver on

%QDIR%\demos\sqlbrowser\release ?

i put only QT += sql on my pro file and all run on qt4.3 beta

wysota
14th May 2007, 00:35
Do you have a static installation of Qt? If not, you don't need Q_IMPORT_PLUGIN or the changes to the project file, just follow the article in our wiki about enabling MySQL support for Qt.

darksaga
14th May 2007, 00:39
can you see the mysql driver on

%QDIR%\demos\sqlbrowser\release ?

i put only QT += sql on my pro file and all run on qt4.3 beta

it's just the QODBC & QSQLITE driver that the driver combobox shows if i run the demo.

i used the QT += sql flag from the start in my project....

i know there is an option that compiles the mysql driver during your first "installation (compilation)".

maybe you used that flag, i didn't.

patrik08
14th May 2007, 09:31
it's just the QODBC & QSQLITE driver that the driver combobox shows if i run the demo.
i used the QT += sql flag from the start in my project....
.

You qt4 installation dont have mysql ... otherwise on %QDIR%\demos\sqlbrowser\release textfield driver mysql is visible!

Move your visual compiler to Trash if visual studio is to hard to handle .. and begin on mingw compiler http://www.mingw.org/ ....

After you have get compiler.... and minimal sys.. (like a linux console emulator you can compile all)
cd dir libmysql.lib

reimp -d libmysql.lib
dlltool -k --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a
dlltool --input-def libmysql.def --dllname libmysql.dll --output-lib c:\MingW\lib\libmysql.a


now put mysql include to mingw include dir and run..

version qt4.3 ...

configure -qt-sql-mysql -qt-sql-odbc -qt-sql-sqlite -qt-gif -qt-tif -qt-libpng -qt-libjpeg
make


cd to %QDIR%\demos\sqlbrowser\release and you can see mysql driver work...
Visual studio have to much option and button ... and confusion ...
I have all two compiler on two pc ... but 90% i work only on mingw ... is more easy...

darksaga
14th May 2007, 18:23
Do you have a static installation of Qt? If not, you don't need Q_IMPORT_PLUGIN or the changes to the project file, just follow the article in our wiki about enabling MySQL support for Qt.

have a shared installation, so a solution using q_import_plugin is obsolete

so I tried the followin steps:

1.)
- followed the article the wiki about enabling MySQL support link (http://wiki.qtcentre.org/index.php?title=Building_the_QMYSQL_plugin_on_Wind ows_using_MinGW)

did exactly as in the description:

- compiles fine, qsqlmysql.dll is created, qsqlmysql.dll and libqsqlmysql.a files are in the %QTDIR%/plugins/ directory
- copied libmysql.dll file from the MySQL installation's bin directory to %QTDIR%/bin

result --> QSqlDatabase: QMYSQL driver not loaded

2.)
after that i decided to install & compile everything from scratch:
- installed new mysql-5.0.41-win32 server
- downloaded qt-win-opensource-src-4.2.3.zip & acs-4.2.3-patch1.zip (visual studio patch)

then proceeded exactly as in the "Qt4 with Visual Studio" tutorial link (http://wiki.qtcentre.org/index.php?title=Qt4_with_Visual_Studio)

following qt compile configuration
qconfigure msvc.net -prefix C:\qt4shared -qt-sql-mysql -I C:\mysql\include -L C:\mysql\lib\opt

during compilation an error occurs while creating the qtsqld4.dll with the following error:

http://img182.imageshack.us/img182/1972/errormi5.th.jpg (http://img182.imageshack.us/my.php?image=errormi5.jpg)

if i do not use the -qt-sql-mysql flag everything finishes fine, but i do not have mysql support.

3.)
tried another attempt with a fresh compiled qt (without -qt-sql-mysql flag) and proceeded as in the wiki about enabling MySQL support link (http://wiki.qtcentre.org/index.php?title=Building_the_QMYSQL_plugin_on_Wind ows_using_MinGW)
but the result still is the same --> QSqlDatabase: QMYSQL driver not loaded

following questions arise:

- is the mysql-5.0.41-win32 server not compatible with qt 4.2.x ?

- is the acs-4.2.3-patch1.zip (visual studio patch) flawed at some script?

the patch modifies the src/sql/sql.pro file:

original:

TARGET = QtSql
QPRO_PWD = $$PWD
QT = core
DEFINES += QT_BUILD_SQL_LIB
win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x62000000

include(../qbase.pri)

DEFINES += QT_NO_CAST_FROM_ASCII
PRECOMPILED_HEADER = ../corelib/global/qt_pch.h
SQL_P = sql

include(kernel/kernel.pri)
include(drivers/drivers.pri)
include(models/models.pri)


modified:

TARGET = QtSql
QPRO_PWD = $$PWD
QT = core
DEFINES += QT_BUILD_SQL_LIB
win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x62000000
win32-borland:QMAKE_LFLAGS += /b:0x62000000

include(../qbase.pri)

DEFINES += QT_NO_CAST_FROM_ASCII
PRECOMPILED_HEADER = ../corelib/global/qt_pch.h
SQL_P = sql

include(kernel/kernel.pri)
include(drivers/drivers.pri)
include(models/models.pri)


maybe somebody can figure out more ???


Visual studio have to much option and button ... and confusion ...
I have all two compiler on two pc ... but 90% i work only on mingw ... is more easy...
I don't think its that bad, an I'm used to it.

And until now I had no prob using QT in Visual studio... ;)

wysota
15th May 2007, 11:09
have a shared installation, so a solution using q_import_plugin is obsolete

so I tried the followin steps:

1.)
- followed the article the wiki about enabling MySQL support link (http://wiki.qtcentre.org/index.php?title=Building_the_QMYSQL_plugin_on_Wind ows_using_MinGW)

did exactly as in the description:

- compiles fine, qsqlmysql.dll is created, qsqlmysql.dll and libqsqlmysql.a files are in the %QTDIR%/plugins/ directory
- copied libmysql.dll file from the MySQL installation's bin directory to %QTDIR%/bin

result --> QSqlDatabase: QMYSQL driver not loaded
Did you empty the plugin cache?

- is the mysql-5.0.41-win32 server not compatible with qt 4.2.x ?
It should work fine provided that it is built with the same compiler. AFAIK, MinGW dlls won't work with MSVC dlls. Was this MySQL compiled with MSVC?

- is the acs-4.2.3-patch1.zip (visual studio patch) flawed at some script?
The script doesn't have anything to do with this.

maybe somebody can figure out more ???
I think it's fine. The linker just can't find a symbol needed. It's definitely a compiler issue, so please try using a different compiler in one of the two places (Qt or MySQL).