PDA

View Full Version : QMYSQL loading problem



ridgesoft
9th May 2007, 02:09
Hi,

I have built and compiled an application using VC++ 2005 and the QMYSQL plugin and it works on my development machine just fine. However, when I move the application (debug version) to a computer that has the MySQL server running on it, the QMYSQL driver won't load. Does anyone have any ideas? thanks.

Daniel

fengtian.we
20th May 2007, 11:30
I have this problem too:

my code:
#include <QApplication>
#include <QtGui>
#include <QtSql>

int main(int argc,char *argv[])
{
QApplication qapp(argc,argv);
QTextEdit display;
display.resize(400, 160);
display.show();

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("111111");
bool ok = db.open();

return qapp.exec();
}


my error info:
1>------ Build started: Project: MsnGeter, Configuration: Debug Win32 ------
1>Performing Makefile project actions
1>Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
1>Copyright (C) Microsoft Corporation. All rights reserved.
1> cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"C:/Qt/4.2.2/include/QtCore" -I"C:/Qt/4.2.2/include/QtCore" -I"C:/Qt/4.2.2/include/QtGui" -I"C:/Qt/4.2.2/include/QtGui" -I"C:/Qt/4.2.2/include" -I"." -I"C:/Qt/4.2.2/include/ActiveQt" -I"debug" -I"." -I"c:\Qt\4.2.2\mkspecs\win32-msvc2005" -Fodebug\ @C:\DOCUME~1\Liu\LOCALS~1\Temp\nmA0.tmp
1>main.cpp
1>.\main.cpp(17) : warning C4189: 'ok' : local variable is initialized but not referenced
1> link /LIBPATH:"c:\Qt\4.2.2\lib" /NOLOGO /DEBUG /DEBUG /MANIFESTFILE:"debug\MsnGeter.intermediate.manifest" /SUBSYSTEM:WINDOWS /OUT:debug\MsnGeter.exe @C:\DOCUME~1\Liu\LOCALS~1\Temp\nmA1.tmp
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QSqlDatabase::~QSqlDatabase(void)" (__imp_??1QSqlDatabase@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall QSqlDatabase::open(void)" (__imp_?open@QSqlDatabase@@QAE_NXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QSqlDatabase::setPassword(class QString const &)" (__imp_?setPassword@QSqlDatabase@@QAEXABVQString@@ @Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QSqlDatabase::setUserName(class QString const &)" (__imp_?setUserName@QSqlDatabase@@QAEXABVQString@@ @Z) referenced in function _main
1>NMAKE : fatal error U1077: '"c:\Program Files\Microsoft Visual Studio 8\VC\bin\link.EXE"' : return code '0x460'
1>Stop.
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QSqlDatabase::setDatabaseName(class QString const &)" (__imp_?setDatabaseName@QSqlDatabase@@QAEXABVQStri ng@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QSqlDatabase::setHostName(class QString const &)" (__imp_?setHostName@QSqlDatabase@@QAEXABVQString@@ @Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QSqlDatabase __cdecl QSqlDatabase::addDatabase(class QString const &,class QString const &)" (__imp_?addDatabase@QSqlDatabase@@SA?AV1@ABVQStrin g@@0@Z) referenced in function _main
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static char * QSqlDatabase::defaultConnection" (__imp_?defaultConnection@QSqlDatabase@@2PADA)
1>debug\MsnGeter.exe : fatal error LNK1120: 8 unresolved externals
1>Project : error PRJ0019: A tool returned an error code from "Performing Makefile project actions"
1>Build log was saved at "file://c:\Documents and Settings\Liu\My Documents\Visual Studio 2005\Projects\MsnGeter\MsnGeter\Debug\BuildLog.htm"
1>MsnGeter - 11 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

jpn
20th May 2007, 11:34
fengtian.we, add:

QT += sql
to .pro file.

Only QtCore and QtGui modules are enabled by default. Other modules, like QtSql must be explicitly taken into use like mentioned above (and in the docs (http://doc.trolltech.com/4.2/qtsql#details), of course).

fengtian.we
20th May 2007, 12:06
################################################## ####################
# Automatically generated by qmake (2.01a) ??? ?? 20 18:50:56 2007
################################################## ####################

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
QT += sql //I add it here,is ok?? :)

# Input
SOURCES += main.cpp

fengtian.we
20th May 2007, 12:20
Thank you Sir!!!! I 'm connect to mysql ok.

but:
at the VS2005,need to set the "Build Command Line",
I think i shoud set it is:

qmake -project //if file count or name chanaged,than shoud update the .pro file isn't
qmake
nmake /f Makefile.Debug

So I think can't use the VS2005's Debug function.I will use the command line(nmake)

(excuse for my Chinese English :))

fengtian.we
20th May 2007, 12:39
Can I use the Sql Module without chanage .pro file?

My Case:

I use the MSVS 2005,QT 4.2.2

I set the "Project Property"->"Configuration Properties"->"NMAKE":

Build Command:
qmake -project //because the file count or file name maybe chanag.
qmake
nmake /f Makefile.Debug

but I want use the sql module........//this shoud add "QT += sql " to .pro file.

so ........... Can I use the Sql Module without chanage .pro file?

patrik08
20th May 2007, 12:51
Can I use the Sql Module without chanage .pro file?
so ........... Can I use the Sql Module without chanage .pro file?

Before you connect on any sql device .. you can check:



QStringList drivers = QSqlDatabase::drivers();
std::cout << "### Your sql driver on bord are: " << qPrintable(drivers.join(" ")) << std::endl;
if (!drivers.contains("QMYSQL")) {
std::cout << "### Load QMYSQL Driver Fail!." << std::endl;
return;
}



If the driver is load , you can use it.... if drivers.size() are 0 no driver sql on board .. so simple..:)

fengtian.we
20th May 2007, 14:47
Thank you Patrik08~

I konw now~ :)