PDA

View Full Version : VS2005+Qt4.2.2:Get a Mysql connect error.HELP!!



fengtian.we
20th May 2007, 11:40
VS2005+Qt4.2.2

my code(main.cpp):
#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 ==========




I am not use the vs2005 SP1 patch,because I hear to some problem is in the SP1.

so I compile the mysql plugin again:

>qmake -o Makefile "INCLUDEPATH+=C:\Server\mysql5\include" "LIBS+=C:\Server\mysql5\lib\opt\libmysql.lib" mysql.pro
>nmake //(there is over,I can't any new file production.I think is auto complete)

I think this ok~,so I compile my code again,but I get a same result.

fengtian.we
20th May 2007, 12:00
my envionment variables:

Path=%SystemRoot%\system32;%SystemRoot%;%SystemRoo t%\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;;C:\Qt\4.2.2\bin

QMAKESPEC=win32-msvc2005

QTDIR=C:\Qt\4.2.2

others are default value

fengtian.we
20th May 2007, 12:23
add:

QT += sql

to .pro file.

Thank jpn!!!! 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 )