PDA

View Full Version : undefined reference to QSqlDatabase::defaultConnection



snufrick
14th May 2007, 06:51
Hi, all.
I`m try compile teset program working with SqLite, and get error on every function/member of QSqlDatabase.

code:



#include <QApplication>
#include <QTranslator>
#include <QMessageBox>
#include <QtSql/QSqlError>
#include <QtSql/QSqlRecord>
#include <iostream>
#include <QtDebug>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlTableModel>

class QSqlDatabase;

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSqlDatabase database = QSqlDatabase::addDatabase ("QSQLITE");
database.setDatabaseName ("test_db");
......


Compile progress:


make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
g++ -o sqlite main.o -L/usr/lib -lQtGui -lQtCore -lpthread
main.o: In function `main':
main.cpp: (.text+0xad): undefined reference to `QSqlDatabase::defaultConnection'
main.cpp: (.text+0xe9): undefined reference to `QSqlDatabase::addDatabase(QString const&, QString const&)'
main.cpp: (.text+0x138): undefined reference to `QSqlDatabase::setDatabaseName(QString const&)'
main.cpp: (.text+0x158): undefined reference to `QSqlDatabase::~QSqlDatabase()'
main.cpp: (.text+0x1ea): undefined reference to `QSqlDatabase::~QSqlDatabase()'
collect2: ld returned 1 exit status

Where is my error ?:confused:
Thx for answers.

jpn
14th May 2007, 07:23
To link against the QtSql (http://doc.trolltech.com/4.2/qtsql) module, add this line to your qmake .pro file:

QT += sql