Results 1 to 3 of 3

Thread: Creating new QSqlDatabase

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Creating new QSqlDatabase

    I am trying to connect to a local SQLite database I have for a school project. We are free to use whatever language we want and I use Qt all the time at work, so I decided to use this over Java for me application. I thought by following the documentation, this wouldn't be too difficult but I am having problems. I am running Qt Creator 2.0.1 on Windows 7 with Qt 4.7.0. The following line in my CPP file causes an error:

    Qt Code:
    1. QSqlDatabase database = QSqlDatabase::addDatabase( "QSQLITE" );
    To copy to clipboard, switch view to plain text mode 

    The compilation error I get is:

    :: error: collect2: ld returned 1 exit status
    Commenting this line out lets the code compile successfully. The whole function it is in is this:

    Qt Code:
    1. bool MainWindow::connectToDatabase( )
    2. {
    3. QSqlDatabase database = QSqlDatabase::addDatabase( "QSQLITE" );
    4. return true;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Obviously this function will have more in it later, and I will use a class variable instead of the local object, but if I can't get this simple statement to compile, no sense trying more complex things, yet.

    Any ideas why my code wouldn't compile with this simple line? It is straight out of the documentation with the SQLite driver which from what I understand would have been created by default when I installed Qt Creator.

    Thanks for your help!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Creating new QSqlDatabase

    Most likely you forget
    pro Code:
    1. QT += sql
    To copy to clipboard, switch view to plain text mode 
    in the pro file.

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

    ToddAtWSU (6th February 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Creating new QSqlDatabase

    You are correct. I have not really used .pro files. I originally did everything by hand and with makefiles in UNIX and recently I have used Qt Integrator with Netbeans for Solaris, but they have check mark boxes to select which Qt libraries you need so I just check the SQL library in the properties and don't realize what it does in the background. Thanks for your help!

Similar Threads

  1. QSQLDatabase
    By hoshy in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2009, 15:09
  2. QThread and QSqlDatabase
    By pdoria in forum Qt Programming
    Replies: 1
    Last Post: 6th March 2008, 03:25
  3. QSqlDatabase
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2007, 17:53
  4. QCoreApplication And QSqlDatabase
    By ball in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2006, 07:58
  5. QSqlDatabase
    By raphaelf in forum Qt Programming
    Replies: 10
    Last Post: 10th May 2006, 15:15

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
  •  
Qt is a trademark of The Qt Company.