Results 1 to 7 of 7

Thread: Problem with including Qt libraries

  1. #1
    Join Date
    Aug 2011
    Location
    Denmark
    Posts
    11
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Post Problem with including Qt libraries

    It want to familiarize myself with Qt by building a simple console application that can access a SQLite database. Using http://doc.qt.nokia.com/4.7/sql-connecting.html as a reference, I enter this in Qt Creator:

    Qt Code:
    1. #include <QtSql/QSqlDatabase>
    2.  
    3. int main() {
    4.  
    5. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    When I try to build, I get a number of errors similar to: "/(...)/console-1/main.cpp:-1: error: undefined reference to `QSqlDatabase::defaultConnection".

    What is wrong?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with including Qt libraries

    Do you have QT += sql in .pro file ?

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

    finngruwier (3rd August 2011)

  4. #3
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with including Qt libraries

    You should add the "sql" in your .pro:
    For example:

    Qt Code:
    1. QT += gui core sql
    To copy to clipboard, switch view to plain text mode 

    Hth.

  5. The following user says thank you to NullPointer for this useful post:

    finngruwier (3rd August 2011)

  6. #4
    Join Date
    Aug 2011
    Location
    Denmark
    Posts
    11
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Problem with including Qt libraries

    Thanks. I wonder why this isn't mentioned in the tutorials (searching for '.pro' yields no results). It's also quite strange that you can't even edit this file in Qt Creator itself - trying to do so just opens the project.

  7. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with including Qt libraries

    This is mentioned in documentation for QtSql module:
    To link against the module, add this line to your qmake .pro file:
    QT += sql
    So you cant edit .pro files with Qt Creator ? If I double-click the .pro file (from the Qt Creator), it simply opens in editor window.
    Or maybe you meant when you double-click the .pro file from the system explorer level,it opens Qt Creator ? If so, you'll need to change the application used to open .pro files (its not related to Qt Creator itself, but to your system settings).

  8. The following user says thank you to stampede for this useful post:

    finngruwier (3rd August 2011)

  9. #6
    Join Date
    Aug 2011
    Location
    Denmark
    Posts
    11
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Problem with including Qt libraries

    Yes, I now see that it is mentioned in the reference documentation, but this might not be the first place you go as a beginner :-)

    Concerning opening the file in Qt Creator: I used File > Open File or Project. I didn't have the "Active Projects Pane" on my screen at that time. But now I see that the .pro file can be opened in "Active Projects Pane".

    Thanks again.

  10. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with including Qt libraries

    (...) but this might not be the first place you go as a beginner :-)
    Yes, I know that especially when you start learning new technology you can be tempted to use tutorials in order to achieve quick effects, but IMHO the sooner you get used to Qt documentation, the better for you. It may be an overstatement, but I think 80% of all questions on this forum can be answered by "Read the documentation" Nothing personal, I was a "newbie" too ( and then I learned how to use Assistant ).

Similar Threads

  1. Problem of including Widgets into DLL
    By dsedov in forum Qt Programming
    Replies: 15
    Last Post: 14th July 2021, 23:05
  2. Problem in file including.
    By Niamita in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2011, 12:15
  3. Including and Windows problem
    By isamert in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2011, 00:50
  4. Problem with QGLWidcet including
    By sebap123 in forum Newbie
    Replies: 2
    Last Post: 27th January 2011, 13:21
  5. Including the QT libraries
    By hapheston in forum Installation and Deployment
    Replies: 3
    Last Post: 22nd August 2010, 13:23

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.