PDA

View Full Version : mysql 5 connection



GuL
6th August 2008, 19:29
Im trying to connect to a mysql server with this code:


#include "testemysql1.h"
#include <QSqlDatabase>
#include <QtSql>
#include <QMessageBox>

testeMYSQL1::testeMYSQL1(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
}

testeMYSQL1::~testeMYSQL1()
{

}


void testeMYSQL1::on_pushButton_clicked()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("servidor");
db.setDatabaseName("teste");
db.setUserName("root");
db.setPassword("");
if (!db.open())

QMessageBox::critical(0, tr("Error"), QString("The error:\n%1").arg(db.lastError().text()));

// bool ok = db.open();
//lineEdit
}

But I got this error:


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

Im using QT4.4 Commercial and Visual Studio 2005.

Thanks in advance
Renan

jpn
6th August 2008, 19:39
You don't seem to have the MySQL plugin. See How to Build the QMYSQL Plugin on Windows (http://doc.trolltech.com/4.4/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows).

GuL
6th August 2008, 19:57
But it shouldn't be instaled by default with a commercial version of qt?

jpn
6th August 2008, 20:01
One would assume so, but I don't remember for sure. Which files do you have in %QTDIR%\plugins\sqldrivers?

fnmblot
6th August 2008, 20:02
Don't forget to put the QT+= sql in your project file

GuL
6th August 2008, 20:12
23/04/2008 18:54 372.736 qsqlite4.dll
23/04/2008 18:54 2.062 qsqlite4.lib
23/04/2008 18:54 561.152 qsqlited4.dll
23/04/2008 18:54 2.074 qsqlited4.lib
23/04/2008 19:35 65.536 qsqlmysql4.dll
23/04/2008 19:35 2.088 qsqlmysql4.lib
23/04/2008 19:35 135.168 qsqlmysqld4.dll
23/04/2008 19:35 2.100 qsqlmysqld4.lib
23/04/2008 18:54 86.016 qsqlodbc4.dll
23/04/2008 18:54 2.074 qsqlodbc4.lib
23/04/2008 18:54 159.744 qsqlodbcd4.dll
23/04/2008 18:54 2.088 qsqlodbcd4.lib
23/04/2008 19:36 126.976 qsqlpsql4.dll
23/04/2008 19:36 2.074 qsqlpsql4.lib
23/04/2008 19:36 245.760 qsqlpsqld4.dll
23/04/2008 19:36 2.088 qsqlpsqld4.lib

Those are the files.

jpn
6th August 2008, 20:30
Ok so it is there. What if you open qsqlmysql4.dll to dependency walker (http://www.dependencywalker.com/). Can you see any missing dependencies?

GuL
7th August 2008, 12:40
Well, here is what Dependency Walker has found:

Error: At least one required implicit or forwarded dependency was not found.
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.

LIBMYSQL.DLL and
MSJAVA.DLL


At least LIBMYSQL.DLL I know I have... But where should they be placed?

Renan

spirit
7th August 2008, 13:15
you can put path to mysql directory in PATH variable.
for example:

set PATH=C:\mysql\bin;%PATH%

GuL
7th August 2008, 13:42
libmysql.dll is in my PATH now. Im trying to find MSJAVA.DLL now.

Renan

jpn
7th August 2008, 13:49
libmysql.dll is in my PATH now. Im trying to find MSJAVA.DLL now.

Renan

The libmysql.dll should be enough. msjava.dll can be safely ignored, see dependency walker faq (http://dependencywalker.com/faq.html) for more details.

GuL
7th August 2008, 13:50
Here is the output window in VS2005:

'testeMYSQL1.exe': Loaded 'C:\Documents and Settings\Renan\Meus documentos\Visual Studio 2005\Projects\testeMYSQL1\debug\testeMYSQL1.exe', Symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\Utils\Qt\4.4.0\bin\QtCored4.dll', Symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\msvcp71d.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\msvcr71d.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\Utils\Qt\4.4.0\bin\QtGuid4.dll', Symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\comdlg32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\winspool.drv', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\Utils\Qt\4.4.0\bin\QtSqld4.dll', Symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc 8b3b9a1e18e3b_8.0.50727.762_x-ww_5490cd9f\msvcr80d.dll', Symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc 8b3b9a1e18e3b_8.0.50727.762_x-ww_5490cd9f\msvcp80d.dll', Symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\avgrsstx.dll', No symbols loaded.
'testeMYSQL1.exe': Unloaded 'C:\WINDOWS\system32\avgrsstx.dll'
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\xpsp2res.dll', Binary was not built with debug information.
The thread 'Win32 Thread' (0xa9c) has exited with code 0 (0x0).
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC QPSQL7 QPSQL
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\wdmaud.drv', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\wintrust.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\imagehlp.dll', No symbols loaded.
'testeMYSQL1.exe': Unloaded 'C:\WINDOWS\system32\setupapi.dll'
'testeMYSQL1.exe': Unloaded 'C:\WINDOWS\system32\wdmaud.drv'
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\wdmaud.drv', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll', No symbols loaded.
'testeMYSQL1.exe': Unloaded 'C:\WINDOWS\system32\setupapi.dll'
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\msacm32.drv', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\msacm32.dll', No symbols loaded.
'testeMYSQL1.exe': Loaded 'C:\WINDOWS\system32\midimap.dll', No symbols loaded.
The thread 'Win32 Thread' (0xb2c) has exited with code 0 (0x0).


Still no success. :confused:

jpn
7th August 2008, 13:52
Did you restart Visual Studio after modifying PATH? It needs to be restarted in order for it to pick the new environment.

GuL
7th August 2008, 14:00
Yes, I had to do it with Dependency Walker too.

Renan

spirit
7th August 2008, 14:03
try to rebuild mysql plugin.

GuL
7th August 2008, 14:19
Im using a commercial version of QT, shouldn't it be ready to use?

Renan

spirit
7th August 2008, 14:25
please, show content of configure.cache

GuL
7th August 2008, 15:07
where is this file?

Renan

spirit
7th August 2008, 15:09
in root of QTDIR folder, i.e. C:\Qt-4.4.0\configure.cache

GuL
7th August 2008, 15:15
I haven't found this file, but I found this one:

.qmake.cache

QMAKE_QT_VERSION_OVERRIDE = 4
OBJECTS_DIR = tmp\obj\debug_shared
MOC_DIR = tmp\moc\debug_shared
RCC_DIR = tmp\rcc\debug_shared
sql-plugins += odbc sqlite
styles += windows plastique cleanlooks windowsxp windowsvista motif cde
imageformat-plugins += gif tiff jpeg
CONFIG += dist-config large-config medium-config minimal-config small-config full-config build_all debug incremental create_prl link_prl depend_includepath QTDIR_build
QT_BUILD_PARTS = libs tools examples demos docs
QMAKESPEC = C:\utils\Qt\4.4.0\mkspecs\win32-msvc2003
ARCH = windows
QT_BUILD_TREE = C:\utils\Qt\4.4.0
QT_SOURCE_TREE = C:\utils\Qt\4.4.0
DEFINES *= QT_EDITION=QT_EDITION_DESKTOP
QMAKE_MOC = $$QT_BUILD_TREE\bin\moc.exe
QMAKE_UIC = $$QT_BUILD_TREE\bin\uic.exe
QMAKE_UIC3 = $$QT_BUILD_TREE\bin\uic3.exe
QMAKE_RCC = $$QT_BUILD_TREE\bin\rcc.exe
QMAKE_DUMPCPP = $$QT_BUILD_TREE\bin\dumpcpp.exe
QMAKE_INCDIR_QT = $$QT_BUILD_TREE\include
QMAKE_LIBDIR_QT = $$QT_BUILD_TREE\lib

spirit
7th August 2008, 15:22
you have only odbc sqlite plugins installed, I don't see mysql driver.

GuL
7th August 2008, 15:26
So how do I install it?

Renan

spirit
7th August 2008, 15:29
You don't seem to have the MySQL plugin. See How to Build the QMYSQL Plugin on Windows (http://doc.trolltech.com/4.4/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows).

use this post :)

GuL
7th August 2008, 15:34
C:\Utils\Qt\4.4.0\src\plugins\sqldrivers>qmake -o Makefile "INCLUDEPATH+=C:\Utils\MySQL5\include" "LIBS+=C:\Utils\MySQL5\lib\opt\l
ibmysql.dll" mysql.pro
Cannot find file: mysql.pro.


Renan

spirit
7th August 2008, 15:42
libmysql.lib don't dll
worng path, it should be like this

cd %QTDIR%\src\plugins\sqldrivers\mysql

GuL
7th August 2008, 15:45
another error:

C:\Utils\Qt\4.4.0\src\plugins\sqldrivers\mysql>qmake -o Makefile "INCLUDEPATH+=C:\Utils\MySQL5\include" "LIBS+=C:\Utils\MySQL5\lib
\opt\libmysql.lib" mysql.pro

C:\Utils\Qt\4.4.0\src\plugins\sqldrivers\mysql>nmake

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin\nmake .exe -f Makefile.Debug all

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

rc -D_DEBUG -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_EDITION=QT_EDITION_DESKTOP -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FR
OM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -fo tmp\obj\debug_shared\qsqlmysqld_resource.res qsql
mysqld_resource.rc
qsqlmysqld_resource.rc(4) : fatal error RC1015: cannot open include file 'winver.h'.
NMAKE : fatal error U1077: 'C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin\rc.E XE' : return code '0x1'
Stop.
NMAKE : fatal error U1077: 'C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin\nmak e.exe' : return code '0x2'
Stop.

C:\Utils\Qt\4.4.0\src\plugins\sqldrivers\mysql>

spirit
7th August 2008, 15:55
did you set INCLUDE & LIB for VS?

GuL
7th August 2008, 16:30
here is my PATH, if thats what you are asking:

PATH

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\sy stem32\WBEM;C:\Utils\python25\;C:\Utils\Qt\4.4.0\b in;C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin;C: \Utils\MicrosoftVisualStudio8\VC\bin;C:\Utils\Micr osoftVisualStudio8\VC;C:\Utils\MySQL5\bin

Renan

spirit
7th August 2008, 16:34
this is PATH variable and I asked INCLUDE and LIB variables, anyway you should set these variables you can copy them from

VSDIR\Common7\Tools\vsvars32.bat

GuL
7th August 2008, 16:58
PATH:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\sy stem32\WBEM;C:\Utils\python25\;C:\Utils\Qt\4.4.0\b in;C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin;C: \Utils\MicrosoftVisualStudio8\VC\bin;C:\Utils\Micr osoftVisualStudio8\VC;C:\Utils\MySQL5\bin

INCLUDE:
C:\Utils\MicrosoftVisualStudio8\VC\ATLMFC\INCLUDE; C:\Utils\MicrosoftVisualStudio8\VC\INCLUDE;C:\Util s\MicrosoftVisualStudio8\VC\PlatformSDK\include;C: \Utils\MicrosoftVisualStudio8\SDK\v2.0\include

LIB:
C:\Utils\MicrosoftVisualStudio8\VC\ATLMFC\LIB;C:\U tils\MicrosoftVisualStudio8\VC\LIB;C:\Utils\Micros oftVisualStudio8\VC\PlatformSDK\lib;C:\Utils\Micro softVisualStudio8\SDK\v2.0\lib


And here is the output again:

C:\Utils\Qt\4.4.0\src\plugins\sqldrivers\mysql>qmake -o Makefile "INCLUDEPATH+=C:\Utils\MySQL5\include" "LIBS+=C:\Utils\MySQL5\lib
\opt\libmysql.lib" mysql.pro

C:\Utils\Qt\4.4.0\src\plugins\sqldrivers\mysql>nmake

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin\nmake .exe -f Makefile.Debug all

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

rc -D_DEBUG -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_EDITION=QT_EDITION_DESKTOP -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FR
OM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -fo tmp\obj\debug_shared\qsqlmysqld_resource.res qsql
mysqld_resource.rc
cl -c -nologo -Zm300 -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_EDITION=QT_EDITI
ON_DESKTOP -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"c:
\utils\Qt\4.4.0\include\QtCore" -I"c:\utils\Qt\4.4.0\include\QtCore" -I"c:\utils\Qt\4.4.0\include\QtSql" -I"c:\utils\Qt\4.4.0\incl
ude\QtSql" -I"c:\utils\Qt\4.4.0\include" -I"c:\Utils\MySQL5\include" -I"c:\utils\Qt\4.4.0\include\ActiveQt" -I"tmp\moc\debug_share
d" -I"." -I"c:\utils\Qt\4.4.0\mkspecs\win32-msvc2003" -Fotmp\obj\debug_shared\ @C:\DOCUME~1\Renan\CONFIG~1\Temp\nm94.tmp
NMAKE : fatal error U1077: 'C:\Utils\MicrosoftVisualStudio8\VC\bin\cl.EXE' : return code '0xc0000135'
Stop.
NMAKE : fatal error U1077: 'C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin\nmak e.exe' : return code '0x2'
Stop.

GuL
8th August 2008, 13:22
Anybody has any ideia why using a commercial version of QT, I got this error?

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

Renan

spirit
8th August 2008, 14:06
you set wrong QMAKESPEC, your QMAKESPEC=win32-msvc2003 but in you case (if you use 2005 VS) must be QMAKESPEC=win32-msvc2005

GuL
8th August 2008, 14:33
ok

I changed my QMAKESPEC, but I still get some errors:


Setting up a Qt environment...
-- QTDIR set to C:\utils\Qt\4.4.0
-- Added C:\utils\Qt\4.4.0\bin to PATH
-- QMAKESPEC set to "win32-msvc2005"
C:\utils\Qt\4.4.0>cd src\plugins\sqldrivers\mysql

C:\Utils\Qt\4.4.0\src\plugins\sqldrivers\mysql>qmake -o Makefile "INCLUDEPATH+=C:\Utils\MySQL5\include" "LIBS+=C:\Utils\MySQL5\lib
\opt\libmysql.lib" mysql.pro

C:\Utils\Qt\4.4.0\src\plugins\sqldrivers\mysql>nmake

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin\nmake .exe -f Makefile.Debug all

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_EDI
TION=QT_EDITION_DESKTOP -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -DQT_THREAD_
SUPPORT -I"c:\utils\Qt\4.4.0\include\QtCore" -I"c:\utils\Qt\4.4.0\include\QtCore" -I"c:\utils\Qt\4.4.0\include\QtSql" -I"c:\utils\
Qt\4.4.0\include\QtSql" -I"c:\utils\Qt\4.4.0\include" -I"c:\Utils\MySQL5\include" -I"c:\utils\Qt\4.4.0\include\ActiveQt" -I"tmp\mo
c\debug_shared" -I"." -I"c:\utils\Qt\4.4.0\mkspecs\win32-msvc2005" -Fotmp\obj\debug_shared\ @C:\DOCUME~1\Renan\CONFIG~1\Temp\nm13.
tmp
NMAKE : fatal error U1077: 'C:\Utils\MicrosoftVisualStudio8\VC\bin\cl.EXE' : return code '0xc0000135'
Stop.
NMAKE : fatal error U1077: 'C:\Utils\MicrosoftVisualStudio8\SDK\v2.0\Bin\nmak e.exe' : return code '0x2'
Stop.

C:\Utils\Qt\4.4.0\src\plugins\sqldrivers\mysql>

Renan

spirit
8th August 2008, 14:56
did you try to build some application from examples?
were they built normally?

GuL
8th August 2008, 15:05
From the examples that came from QT, no. But I was folloing a tutorial to learn QT

http://maven.smith.edu/~thiebaut/tutorials/

And the have compiled fine. This is the first Im trying to connect to a database.

Renan

GuL
11th August 2008, 12:19
Thats interesting: I was with this problem the whole week, and now it worked.

Here is what I did: uninstall MySQL, QT and QT VS Integration. Restart the computer, and then install them all again.

This should do the job. I don't know why this had done it work, but it did. Maybe there is a bug somewhere. I don't know.

Thanks to all that tryied to help.

Renan

ghoust26
17th August 2008, 09:29
Thats interesting: I was with this problem the whole week, and now it worked.

Here is what I did: uninstall MySQL, QT and QT VS Integration. Restart the computer, and then install them all again.

This should do the job. I don't know why this had done it work, but it did. Maybe there is a bug somewhere. I don't know.

Thanks to all that tryied to help.

Renan

Should it be done in some specific order?

GuL
18th August 2008, 15:11
I don't know for sure, but I did in this order:
MySQL, QT and QT VS Integration.

Uninstall and install in that order.

Renan