PDA

View Full Version : Problem with including Qt libraries



finngruwier
2nd August 2011, 21:50
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:



#include <QtSql/QSqlDatabase>

int main() {

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

}


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?

stampede
2nd August 2011, 22:06
Do you have QT += sql in .pro file ?

NullPointer
2nd August 2011, 22:11
You should add the "sql" in your .pro:
For example:



QT += gui core sql


Hth.

finngruwier
3rd August 2011, 08:44
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.

stampede
3rd August 2011, 09:39
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).

finngruwier
3rd August 2011, 10:05
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.

stampede
3rd August 2011, 10:53
(...) 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 ;) ).