PDA

View Full Version : Connecting to my database



miguel_mark
22nd October 2007, 08:54
my problem right now is that i cant connect my database to my program, im using qdevelop and mysql. this is the code that i use:
QString HST = "localhost";
QString USR = "root";
QString PWD = "";
QString DBASE = "rdmssql";
QString DRIVE = "QMYSQL";

QSqlDatabase defaultDB = QSqlDatabase::addDatabase(DRIVE);
defaultDB.setDatabaseName(DBASE);
defaultDB.setUserName(USR);
defaultDB.setPassword(PWD);
defaultDB.setHostName(HST);
defaultDB.open();

and i revceive errors like these:
>>build\main.o(.text+0x1a1):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase17defaultConnectionE'
>>build\main.o(.text+0x1ea):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase11addDatabaseERK7QStringS2 _'
>>build\main.o(.text+0x244):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase15setDatabaseNameERK7QStri ng'
>>build\main.o(.text+0x268):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase11setUserNameERK7QString'
>>build\main.o(.text+0x281):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase11setPasswordERK7QString'
>>build\main.o(.text+0x29a):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase11setHostNameERK7QString'
>>build\main.o(.text+0x2a9):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase4openEv'
>>build\main.o(.text+0x2f0):main.cpp: undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'
>>build\main.o(.text+0x4b5):main.cpp: undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'

please tell me what im doing wrong?

wysota
22nd October 2007, 08:57
You need to add "QT+=sql" line to your .pro file and rerun qmake.

miguel_mark
22nd October 2007, 09:01
where should i place QT+=sql???

wysota
22nd October 2007, 09:11
In your project file - the one that has a .pro extension :)

high_flyer
22nd October 2007, 09:22
just copy the line wysota gave you and paste it in your projects pro file.

EDIT: OOpsss... sorry, should have refreshed my browser. :)

miguel_mark
22nd October 2007, 09:50
thanx...:D it's ok now...

wysota
22nd October 2007, 09:50
If you use Visual Studio integration, you'll need to right click your project entry in solution explorer, choose "Add Qt module" and check "SQL library".