PDA

View Full Version : what should i include to work with QSqlDatabase?



mismael85
5th March 2008, 22:28
hello,
i want to work with QSqlDatabase and QSqlQuery so
i included the following file
#include <QtSql>
but i get a message say :
Can not open include file :QtSql no such file or directory
what is wrong?

pdoria
5th March 2008, 22:33
Hi

you should



#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>


1st one being for database objects
2nd for queries
3rd for meaningful output for any error

HTH,
Pedro Doria Meunier

jpn
6th March 2008, 07:44
Only QtCore and QtGui modules are enabled by default. To add suitable include paths and to link against QtSql module, add this line to your qmake .pro file:

QT += sql

mismael85
6th March 2008, 16:51
i am using visual studio 2005 and there is no .pro file!!!!

jpn
6th March 2008, 16:59
i am using visual studio 2005 and there i no .pro file!!!!
That's a pity. Nobody else can build your project with any other compiler then. Because of that, it is ALWAYS a good idea to maintain a qmake .pro file even if you used this or that IDE.

Provided that you're using the Visual Studio integration, you can open context menu over the project item in solution explorer. There's a menu item to choose Qt modules.

mismael85
6th March 2008, 17:18
i used MinGw with a static version of Qt and i added
Qt += sql
to the *.pro file
and it is also say that there is no such file or directory!!!

jpn
6th March 2008, 17:28
The variable name is QT, not Qt.

mismael85
6th March 2008, 17:38
thank you for your help .
for visual studio i did just as you said and it worked fine.
and for Mingw32-make
i added Qt += sql but it was wrong
because *.pro file is case sensitive and it must be
QT += sql
when i did that every thing worked fine.
thank you again.

mrbalick
25th December 2011, 18:57
Thanks all