PDA

View Full Version : QtSQL - Where is My Database?



feuerball11
16th July 2012, 16:25
Hello There.

I Have an Database from 1Blue, with the table "test"

now i Can connect without problems, but db.tables() says that there are no tables. Why?

My Code (Zensored)



QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName("mysql12.1blu.de");
db.setDatabaseName("***********");
db.setUserName("**********");
db.setPassword("**********");
bool ok = db.open();
qDebug() << db.tables();
qDebug() << db.isValid();
qDebug() << db.isOpen();


And the Return:
()
true
true

So why there are no tables? In phpMyAdmin there are tables!

I hope someone can help me.

MFG feuerball11

PS: Sorry for bad english

wysota
16th July 2012, 18:16
You're using a wrong driver. If you want to connect to a MySQL database, use QMYSQL driver instead of QSQLITE.

feuerball11
17th July 2012, 14:53
Then its not Working. The Programm returns:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC QPSQL7 QPSQL
()
false
false

wysota
17th July 2012, 17:06
Then you need to install the driver or its dependencies.

feuerball11
17th July 2012, 18:34
Sry for the noob question, but where can i get this driver? must everone install this driver how uses my programm, or only i to compile it?

wysota
17th July 2012, 18:50
Check if you have the plugin library available. If yes, then probably all you need is to install MySQL client libraries. If no, you'll need to build the plugin

ChrisW67
18th July 2012, 01:04
If you are using the Qt SDK then you might find this Building the Database Plugins for QtSDK Users wiki page useful in conjunction with the docs that wysota linked to.

You will not need to compile the plugin for every user but you will need to deploy the plugin and the MySQL client libraries with your software.

feuerball11
18th July 2012, 11:04
AT first. I Using Visual Studio 2008

I compiled the plugin again and again. but its not working.

i put qsqlmysqld4.dll and qsqlmysqld4.lib into the folder
C:\Qt\4.8.2\plugins\sqldrivers

but qt says only:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC QPSQL7 QPSQL

can anyone helb me? it cant be so difficult to run this plugin -.-

ChrisW67
18th July 2012, 11:25
You do not have to manually copy anything to install the plugin:


nmake install

does that for you.

The MySQL runtime libraries must be available in the environment (i.e. PATH) of the running program in order to load the plugin.

feuerball11
18th July 2012, 11:28
nmake install was sucsesfull, but it doesent work again...

"Testumgebung.exe": "C:\Qt\4.8.2\plugins\sqldrivers\qsqlmysqld4.dll" geladen, Symbole wurden geladen.
"Testumgebung.exe": "C:\Qt\4.8.2\plugins\sqldrivers\qsqlmysqld4.dll" entladen.
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC QPSQL7 QPSQL

.... this is anoying ...

ChrisW67
18th July 2012, 11:44
The MySQL runtime libraries must be available in the environment (i.e. PATH) of the running program in order to load the plugin.

It might be annoying, but you already have the answer. Just like any other piece of code, the Qt MySQL plugin cannot load if it cannot find the libraries it depends on. These libraries are part of MySQL and nothing to do with Qt itself. Windows has a well documented search mechanism for locating dynamically loaded libraries.

On your development machine you can simply place the MySQL bin directory into the system PATH or the PATH used by your IDE to run the software. (Just like the PostgreSQL libraries must be).

feuerball11
18th July 2012, 11:53
Ok Thanks. It works. Didnt understand the sentence (bad english) but now i understand.

Realy big Thanks :-)

*edit*

ok little problem.. It runs in Debug, but not in release? why that? must i put dll files to the release?

wysota
18th July 2012, 13:46
Did you build the plugin in release mode?

feuerball11
18th July 2012, 13:58
I found it by myself.. now is the problem:

i can build a release version, it runs fine on my pc. but not on other pcs... it starts, but do not connect.

i added many dlls. but nothing helped.

addded this dlls to the exe:

libmysql.dll
qsqlmysql4.dll
qtcore4.dll
qtcored4.dll
gtgui4.dll
qtguid4.dll
qtsql4.dll
qtsqld4.dll


but with all this dlls, it wont connect to the database -.- and i have no way to see the debug log on other pcs with a compiled exe....

but on my pc it works from all destinations...

wysota
18th July 2012, 18:03
Does QSqlDatabase::lastError() return any meaningful information?

ChrisW67
19th July 2012, 02:01
i can build a release version, it runs fine on my pc. but not on other pcs... it starts, but do not connect.
i added many dlls. but nothing helped.
addded this dlls to the exe:

libmysql.dll
qsqlmysql4.dll
qtcore4.dll
qtcored4.dll
gtgui4.dll
qtguid4.dll
qtsql4.dll
qtsqld4.dll

but with all this dlls, it wont connect to the database -.- and i have no way to see the debug log on other pcs with a compiled exe....

but on my pc it works from all destinations...

The qsqlmysql4.dll file should be placed into a subfolder "sqldrivers" next to the program executable. You may need to place libmysql.dll with it (I am not sure).
You do not need to deploy the debug version of the Qt libraries, qtcored4.dll, qtguid4.dll, or qtsqld4.dll, for a release application. Should look like:



C:\Program Files\MyApp\
MyApp.exe
qtcore4.dll
gtgui4.dll
qtsql4.dll
sqldrivers\
qsqlmysql4.dll
libmysql.dll // possibly here, possibly in directory above
imageformats\
...
codecs\
...
iconengines\
...

feuerball11
19th July 2012, 09:12
now it finaly works. thanks. i worked yesterday the hole day on this ****** problem.....

EPIC THX ^^

Lesiok
19th July 2012, 12:31
And enough to read the documentation. In particular this (http://qt-project.org/doc/qt-4.8/deployment.html).

Viper666
20th July 2012, 12:02
nmake install was sucsesfull, but it doesent work again...

"Testumgebung.exe": "C:\Qt\4.8.2\plugins\sqldrivers\qsqlmysqld4.dll" geladen, Symbole wurden geladen.
"Testumgebung.exe": "C:\Qt\4.8.2\plugins\sqldrivers\qsqlmysqld4.dll" entladen.
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC QPSQL7 QPSQL

.... this is anoying ...

Sorry i don't read full thread but why are you not use QODBC driver? i use it with MySql and it work fine