Connecting to my database
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?
Re: Connecting to my database
You need to add "QT+=sql" line to your .pro file and rerun qmake.
Re: Connecting to my database
where should i place QT+=sql???
Re: Connecting to my database
In your project file - the one that has a .pro extension :)
Re: Connecting to my database
just copy the line wysota gave you and paste it in your projects pro file.
EDIT: OOpsss... sorry, should have refreshed my browser. :)
Re: Connecting to my database
thanx...:D it's ok now...
Re: Connecting to my database
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".