PDA

View Full Version : SQLITE include error



Qt Coder
18th June 2009, 09:25
I m using Qt 4.4.3 and I have installed SQLite Maestro (windows OS).

Now I want to connect to DB ,


I have started with some code but getting errroe

Header file is


#ifndef DB_TRANS_H
#define DB_TRANS_H




class DB_TRANS
{
public:
DB_TRANS();
}


#endif


and cpp file is



#include "DB_TRANS.h"
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>



DB_TRANS::DB_TRANS()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName("localhost");
db.setDatabaseName("SE01_DB");
// db.setUserName("mojito");
db.setPassword("SE01");
bool ok = db.open();

if(!ok){
QMessageBox::critical( this, "SE01_DB Database Error",
"Could not connect to the database!\n"
"\n"
"Reported error:\n"
+db.lastError().driverText()+"\n"
+db.lastError().databaseText()+"\n"
+db.databaseName()+"\n");
}
}




these 2 files I have included in my .PRO file.
also included below line in PRO file

QT += sql
But when I compile the program I get below errors



In file included from C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/stddef.h:6,
from ../../../include/QtCore/../../src/corelib/global/qglobal.h:41,
from ../../../include/QtCore/qglobal.h:1,
from ../../../include/QtCore/../../src/corelib/global/qnamespace.h:41,
from ../../../include/QtCore/qnamespace.h:1,
from ../../../include/QtCore/../../src/corelib/kernel/qobjectdefs.h:41,
from ../../../include/QtCore/qobjectdefs.h:1,
from ../../../include/QtGui/../../src/gui/kernel/qwindowdefs.h:41,
from ../../../include/QtGui/qwindowdefs.h:1,
from ../../../include/QtGui/../../src/gui/kernel/qwidget.h:41,
from ../../../include/QtGui/qwidget.h:1,
from ../../../include/QtGui/../../src/gui/dialogs/qdialog.h:41,
from ../../../include/QtGui/qdialog.h:1,
from ../../../include/QtGui/../../src/gui/dialogs/qmessagebox.h:41,
from ../../../include/QtGui/qmessagebox.h:1,
from ../../../include/QtGui/QMessageBox:1,
from DB_TRANS.cpp:2:
C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/include/stddef.h:151: error: extraneous `int' ignored
In file included from C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/char_traits.h:46,
from C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/string:47,
from ../../../include/QtCore/../../src/corelib/tools/qstring.h:56,
from ../../../include/QtCore/qstring.h:1,
from ../../../include/QtCore/../../src/corelib/kernel/qobject.h:44,
from ../../../include/QtCore/qobject.h:1,
from ../../../include/QtGui/../../src/gui/kernel/qwidget.h:42,
from ../../../include/QtGui/qwidget.h:1,
from ../../../include/QtGui/../../src/gui/dialogs/qdialog.h:41,
from ../../../include/QtGui/qdialog.h:1,
from ../../../include/QtGui/../../src/gui/dialogs/qmessagebox.h:41,
from ../../../include/QtGui/qmessagebox.h:1,
from ../../../include/QtGui/QMessageBox:1,
from DB_TRANS.cpp:2:
C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_algobase.h: In static member function `static _Tp* std::__copy_backward_dispatch<_Tp*, _Tp*, __true_type>::copy(const _Tp*, const _Tp*, _Tp*)':
C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_algobase.h:407: error: no match for 'operator*' in 'sizeof (_Tp) * _Num'
In file included from C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/string:48,
from ../../../include/QtCore/../../src/corelib/tools/qstring.h:56,
from ../../../include/QtCore/qstring.h:1,
from ../../../include/QtCore/../../src/corelib/kernel/qobject.h:44,
from ../../../include/QtCore/qobject.h:1,
from ../../../include/QtGui/../../src/gui/kernel/qwidget.h:42,
from ../../../include/QtGui/qwidget.h:1,
from ../../../include/QtGui/../../src/gui/dialogs/qdialog.h:41,
from ../../../include/QtGui/qdialog.h:1,
from ../../../include/QtGui/../../src/gui/dialogs/qmessagebox.h:41,
from ../../../include/QtGui/qmessagebox.h:1,
from ../../../include/QtGui/QMessageBox:1,


and many more errors like this


I m not able to diagnose the problem,

Tell me the steps to connect to sQLite database

lyuts
18th June 2009, 11:13
Your class definition doesn't end with ';'.