[Solved] Problem with including QtSql
-
yes right but my other example is working fine
here it is
@
#include <QApplication>
#include <QtSql>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setDatabaseName("testTwo"); db.setUserName("root"); db.setPassword("xxxxxx"); bool ok = db.open(); //qDebug() << db.lastError().text(); //qDebug() << ok; QSqlQuery query(db); query.exec("SELECT * FROM testTable"); while(query.next()) { QString firstName = query.value(0).toString(); QString secondName = query.value(1).toString(); //int id = query.value(2).toInt(); qDebug() << "First Name: " << firstName << "Last Name:" << secondName << "\n"; //qDebug() << db.lastError(); } return 0;
}
@
-
your pro files are similar? try clean build?
-
I meant, you have one project with working Qt sql code, and another failing to find the includes, so just compare the .pro files and see if they are similar.
Next, in Qt Creator, go to Build menu and select "Clean Project" option and then rebuild ... sometimes this could help ...
-
i also did that clean project from build menu but still the same problem
i think both pro files are different
this .pro is for that example which is working
@
#-------------------------------------------------Project created by QtCreator 2010-10-10T13:05:29
#-------------------------------------------------
QT += core gui
QT += sql
TARGET = dbExample
TEMPLATE = appSOURCES += main.cpp
db.cppHEADERS += db.h
connection.hFORMS += db.ui
@
and this is the one which is not working
@
#-------------------------------------------------Project created by QtCreator 2010-10-12T01:37:23
#-------------------------------------------------
QT += core gui
QT += sql;TARGET = untitled
TEMPLATE = appSOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui
@
-
The second one has a semi colon after SQL, try removing that.
You could use this directly
@
QT += core gui sql
@
better to have one definition instead of multiple, just easier to maintain -
good to hear that