Results 1 to 2 of 2

Thread: undefined reference to QSqlDatabase::defaultConnection

  1. #1
    Join Date
    May 2007
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default undefined reference to QSqlDatabase::defaultConnection

    Hi, all.
    I`m try compile teset program working with SqLite, and get error on every function/member of QSqlDatabase.

    code:

    Qt Code:
    1. #include <QApplication>
    2. #include <QTranslator>
    3. #include <QMessageBox>
    4. #include <QtSql/QSqlError>
    5. #include <QtSql/QSqlRecord>
    6. #include <iostream>
    7. #include <QtDebug>
    8. #include <QtSql/QSqlQuery>
    9. #include <QtSql/QSqlTableModel>
    10.  
    11.  
    12. int main(int argc, char *argv[])
    13. {
    14. QApplication app(argc, argv);
    15. QSqlDatabase database = QSqlDatabase::addDatabase ("QSQLITE");
    16. database.setDatabaseName ("test_db");
    17. ......
    To copy to clipboard, switch view to plain text mode 

    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 ?
    Thx for answers.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: undefined reference to QSqlDatabase::defaultConnection

    To link against the QtSql module, add this line to your qmake .pro file:
    QT += sql
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    snufrick (14th May 2007)

Similar Threads

  1. Compiling error
    By Foobar in forum Newbie
    Replies: 2
    Last Post: 17th March 2007, 23:02
  2. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15
  3. Strange error while using Q3Canvas
    By Kapil in forum Newbie
    Replies: 13
    Last Post: 15th June 2006, 19:36
  4. undefined reference to fftw libraries
    By kmyadam in forum General Programming
    Replies: 2
    Last Post: 9th March 2006, 01:01
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.