PDA

View Full Version : Connection to MySQL - windows



Peter34
16th October 2006, 05:57
Hi everybody,

Like many people in this forum, I have problem connecting to a mysql databasis.

I have tried every tutorials I can find on internet but I have still the same error :
"In file included from main.cpp:26:
../../../sql/drivers/mysql/qsql_mysql.h:34:19: mysql.h No such file or directory"

I have Qt 4.1.1 OS on windows XP and MySQL 5.0.

I did the steps listed at this adress:
http://qtfr.org/forum/viewtopic.php?pid=8357 (in french)
(or the same in english: http://www.korone.net/bbs/board.php?bo_table=qt_lecture&wr_id=173)

For me, this is:

cd c:\program*\mysql\mysql*\lib\opt
reimp -d libmysql.lib
dlltool -k --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a

cd Qt\4.1.1
configure -plugin-sql-mysql
(I also tried: configure -plugin-sql-mysql -I C:\program*\mysql\mysql*\INCLUDE)

cd c:\qt\4.1.1\src\plugins\sqldrivers\mysql
qmake -o Makefile "INCLUDEPATH+=C:\program*\mysql\mysql*\INCLUDE" "LIBS+=-LC:\program*\mysql\mysql*\LIB\OPT -lmysql" mysql.pro

cd Qt\4.1.1
make

And I get the error:
"mysql.h No such file or directory"

Like I said before, I have tried every thing I can and I don't know how to fix this error. So if someone can help me, I would really apreciate it.

Thanks.

wysota
16th October 2006, 09:42
You can't use wildcards ("*"), you have to provide full path. Unfortunately something in the chain doesn't like whitespaces in paths, so you should move the files needed (or the whole installation) to another place - without white spaces and point the compilation there.

Peter34
16th October 2006, 19:58
OK thanks, I made a new instalation of MySQL in a path without whitespaces, and this time the compilation runed without error.

But still, when I try to connect to the database, I get the error:
"Driver not loaded Driver not loaded"

Here is the code I use to make the connection:

#include <QtGui>
#include <QtSql>
#include <QMessageBox>
#include <QSqlDatabase>

inline bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setUserName("root");
db.setPassword("T23Y45");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"), db.lastError().text());
return false;
}
return true;
}

Is there something wrong?

wysota
16th October 2006, 20:32
Please search this forum for issues related to MySQL driver and try to use solutions provided there. Maybe some of them will help. If not, then come back to this thread and try to describe what you tried and what were the results. Probably either the driver or some of its dependencies can't be found by your system.

fpujol
17th October 2006, 11:18
Hi,

Thank you :) After reading very posts. I have my driver loaded but I don't understand something. I have a question. MYSQL driver is loaded if I have Instaled mysql in the default C:\archivos de programa\mysql\mysql\mysql server 5.0 but also I need to have copy in C:\mysql\include ... and C:\mysql\lib ..... because qmake don't like spaces like C:\archivos de prova ex: qmake -o Makefile INCLUDEPATH+=C:\archivos de programa\mysql....

Also I tried to install mysql to c:\mysql but I have a problem with driver not loaded. So I need to have two directories of mysql one is for default path installation and other for do the qmake

Thank you

wysota
17th October 2006, 12:08
because qmake don't like spaces
I don't think it's qmake, more probably make itself.


Also I tried to install mysql to c:\mysql but I have a problem with driver not loaded. So I need to have two directories of mysql one is for default path installation and other for do the qmake

The problem is that during compilation time the compiler has to be able to find proper include files and libraries so that it can build the plugin. Because of some feature/bug, the build process doesn't accept whitespaces in path names. This is one thing.

But the problem is also that those mysql libraries have to be found by the system, so that it can initialise the plugin when it is to be used by Qt. To do that, the system needs to be informed where those libraries are (that's what the installation process of MySQL does - it registers those libraries within the system).

If you install MySQL in a place where both of the above mentioned conditions are met, you can have a single directory and a working driver without any special actions from your side. But if you fail to meet one of those conditions, the driver will either not compile or not run and you have to "patch" your system by copying appropriate files to appropriate places.

So let me say it one last time, so that everyone having problems with MySQL driver under Windows can see the issue:

Problems with compiling/running the MySQL (or any other) driver are not related to Qt but to faulty installation of MySQL or to bugs within the tool chain used to build the driver.
You can get rid of all the problems by pointing MySQL installation to a proper (non-default) place, that doesn't contain whitespaces, like C:\MySQL in the first place!

Peter34
20th October 2006, 17:15
Hi,

I actually installed MySQL in C:\MySQL. All the process of compilation went find:

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

cd c:\Qt\4.1.1
configure -plugin-sql-mysql -I C:\mysql\INCLUDE

cd c:\qt\4.1.1\src\plugins\sqldrivers\mysql
qmake -o Makefile "INCLUDEPATH+=C:\mysql\INCLUDE " "LIBS+=-LC:\mysql\LIB\OPT -lmysql" mysql.pro

cd C:\Qt\4.1.1
make

But there is still this damn error "driver not loaded".

So I used QSqlDatabase::drivers() and found out there is no driver loaded.

wysota
20th October 2006, 17:23
Is C:\MySQL\lib\opt in your system's library path?

Peter34
20th October 2006, 18:14
Ok, actually MySQL is installed in C:\MySQL\MySQL_server_5.0.
I guess it's not a problem compared to C:\MySQL?

Now, yes there is : C:\MySQL\MySQL_Server_5.0\lib\opt in the variable path.
(start->control panel->system->advanced->environment variables->path)

wysota
20th October 2006, 22:52
Use a dependency walker to see if the driver can find all its dependencies.

Peter34
26th October 2006, 20:57
Thanks for your help but actually I don't really know where to look for the driver. :confused:

But I tried to run the dependency walker on my program (myQtProgram.exe) and here is what it says:
EFSADU.DLL: Error opening file, impossible to find the file
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

Then I tried to look for EFSADU.DLL on my computer but I don't have it.

jacek
26th October 2006, 21:09
But I tried to run the dependency walker on my program (myQtProgram.exe)
Try running it on the plugin with QMYSQL driver.

wysota
26th October 2006, 21:49
Thanks for your help but actually I don't really know where to look for the driver. :confused:

It should be in plugins\sqldrivers folder of your Qt installation. And you don't have to look for it manually - use a file search function your operating system offers. The file will probably be called qmysql.dll

Peter34
26th October 2006, 22:27
Ok there are 2 files in Plugins\SqlDrivers:
qsqlmysql.dll and qmysqld.dll.

I run the dependancy walker on both of them and the answer is always the same:

EFSADU.DLL: Error opening file, impossible to find the file
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

mm78
26th October 2006, 22:45
Ok there are 2 files in Plugins\SqlDrivers:
qsqlmysql.dll and qmysqld.dll.


These are the release and debug builds of the driver.

You didn't forget:


QApplication app(argc, argv);

in your main() function, did you?

Peter34
27th October 2006, 04:14
These are the release and debug builds of the driver.
That's good to know.

Yes I put:
QApplication app(argc, argv);
in the main function.
Actually I am working with exemples from a Qt book so the syntax should be ok.

Peter34
30th October 2006, 04:37
Does someone has an idea of what is going wrong.
I read that window XP Home doesn't have the EFSADU.DLL file. And that may be the raison why the plugin doesn't work.. :confused:

wysota
30th October 2006, 07:47
I assure you the plugin works on WindowsXP Home.

Peter34
30th October 2006, 18:54
Finally! This is working! :)
I just reinstall mysql in C:\MySQL then did the configuration and compilation, and it worked fine.

Thanks for your help Wysota.