cannot connect to QSqldatabase
hey all,
I'm using Qt4.4.1 and trying to connect to mysql database using the following code:
Code:
db.setHostName("acidalia");
db.setDatabaseName("customdb");
db.setUserName("mojito");
db.setPassword("J0a1m8");
bool ok = db.open();
i also include
Code:
#include <QtSql>
#include <QSqlDatabase>
but i get the following error:
Code:
src\mainwindowimpl.cpp: In member function `void MainWindowImpl::fileNew()':
src\mainwindowimpl.cpp:124: error: `QSqlDatabase' undeclared (first use this function)
src\mainwindowimpl.cpp:124: error: (Each undeclared identifier is reported only once for each function it appears in.)
src\mainwindowimpl.cpp:124: error: expected `;' before "db"
src\mainwindowimpl.cpp:125: error: `db' undeclared (first use this function)
src\mainwindowimpl.cpp:129: warning: unused variable 'ok'
mingw32-make.exe[1]: *** [build/mainwindowimpl.o] Error 1
e:\qt\MinGW\bin\mingw32-make.exe: *** [release] Error 2
i know it's been answered before in this forum here: http://www.qtcentre.org/forum/f-newb...blem-5861.html
but i followed the solution and yet it didn't work for me.
Any ideas!?
thanks in advance.
Re: cannot connect to QSqldatabase
did you added in your .pro file?
Re: cannot connect to QSqldatabase
well, this issue is fixed now.
another thing is, the plugin issue, i get this msg when i run the executable:
there is a solution which said the following:
is this true? Do i need to compile qt from source with these arguments in order to get sql to work?
btw i have 4 dll files in Qt\4.4.1\plugins\sqldrivers which are:
1.qsqlite4.dll
2.qsqlited4
3.qsqlodbc4.dll
4.qsqlodbc4d.dll
which i copied to my Qt\4.4.1\bin
thanks.
Re: cannot connect to QSqldatabase
Quote:
Originally Posted by
mave-rick
there is a solution which said the following:
is this true? Do i need to compile qt from source with these arguments in order to get sql to work?
yup, you need to compile mysql plugin.
Quote:
Originally Posted by
mave-rick
btw i have 4 dll files in Qt\4.4.1\plugins\sqldrivers which are:
1.qsqlite4.dll
2.qsqlited4
3.qsqlodbc4.dll
4.qsqlodbc4d.dll
which i copied to my Qt\4.4.1\bin
you should't do this, Qt find this dll by itself.