View Full Version : SQL-Module

21st January 2006, 15:15
I need access to a MySQL-Database in one of my Qt 4.0.0 programmes. I got a message: "Driver not loaded, Driver not loaded", when I tried the following code:

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
bool ok = db.open();
if(ok)setText("it works");

In the docs, it says:
You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MYSQL):

cd %QTDIR%\src\plugins\sqldrivers\mysql
I have never installed any MySQL and I don't understand why I have to do this. After all, I don't necessarily want to access a database on my computer, it could also be on a remote computer where MySQL is installed. So I think I must have got something wrong. Can you tell me what to do?


21st January 2006, 15:35
Its not wrong. You dont must install MySql server on localhost as you think;)
You must do qmake,nmake for build MySql driver, what give access you to MySql database.

21st January 2006, 17:24
Ok, now I've installed MySQL 5.0. All the files can now be found on my computer. I ran:

C:\Qt\4.0.0\src\plugins\sqldrivers\mysql>qmake -o Makefile "INCLUDEPATH+=C:\Prog
ramme\MySQL\MySQLServer5.0\include" "LIBS+=C:\Programme\MySQL\MySQLServer5.0\lib
\opt\LIBMYSQL.LIB" mysql.pro

And I got the mistake that mysql.h could not be found. So I copied all the .cpp and .h files to C:\Qt\4.0.0\src\plugins\sqldrivers\mysql and to C:\Qt\4.0.0\plugins\sqldrivers and I changed #include <mysql.h> into #include "mysql.h" and then this worked. But I got another error-message, and I don't know how to handle it:

C:\mingw\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\ mingw32\bin\ld.exe: cannot fin
d -lmysql.lib

What to do?

21st January 2006, 21:21
Look into the FAQ (http://www.qtcentre.org/forum/faq.php?faq=qt_compiling_mysql_plugin_category#faq _qt_mysql_no_mysql_lib)

22nd January 2006, 16:29
Thank you for the FAQs. According to them, I tried: 'C:\Qt\4.0.0\>configure "-qt-sqlmysql" "-IC:\Programme\MySQL\MySQLServer5.0\include\" "LC:\Programme\mysql\mysqlserver5.0\include\" '.

Now it took ages to "Read" files etc., and after some time my windows stopped working ...
Before trying it a second time, I wanted to ask whether this is really the proper way. I thought I must have done something wrong if I have to wait for 2 hours while my computer is working on the single command "configure ..." (see above) just to get MySQL-Access? - Doesn't this go faster?


22nd January 2006, 16:57
I tried: 'C:\Qt\4.0.0\>configure "-qt-sqlmysql" "-IC:\Programme\MySQL\MySQLServer5.0\include\" "LC:\Programme\mysql\mysqlserver5.0\include\" '.
Shouldn't this be:
C:\...>configure "-qt-sql-mysql" ..."-LC:\Prog..."

Doesn't this go faster?
Do you have anti-virus software installed?

22nd January 2006, 17:07
No, there is no antivirus-software. But perhaps I explain what I've done so far, perhaps something else was wrong: I downloaded and installed the mysql 5.0 package from mysql.com and installed it with the provided installer. Then I launched configure ... . Did I forget a step in between?

22nd January 2006, 17:24
"configure" shouldn't run longer than 5-10 minutes. You can speed it up a little by passing "-fast" switch to it. It'll skip generating makefiles for examples then. Certainly it shouldn't run for two hours... What hardware do you have?