I just started working with Qt (in C++), so I followed a "hello, world" example I found online. I created the program hello.cpp in the directory hello:
#include <QtGui>
int main(int argc, char *argv[]) {
QApplication app (argc, argv);
QLabel label ("Hello, world!");
label.show();
return app.exec();
}
I ran:
qmake -project
qmake hello.pro
make
and everything compiled correctly and I was able to run ./hello. Then, being an adventurous person, I tried modifying the file:
#include <QtGui>
#include <QtWebKit>
int main(int argc, char *argv[]) {
QApplication app (argc, argv);
QLabel label ("Hello, world!");
QWebPage page;
label.show();
return app.exec();
}
I reran the three commands, but now when I run make I get the following error:
hello.cpp:2: fatal error: QtWebKit: No such file or directory
compilation terminated.
make: *** [hello.o] Error 1
I checked out the Makefile and the INCPATH variable was defined as
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I.
It is noticeably missing -I/usr/include/qt4/QtWebKit. The LIBS variable was also missing -lQtWebKit. Adding these manually causes the compilation to succeed. What am I doing wrong? What do I need to add to make qmake generate the correct Makefile?
You need to add:
QT += webkit
to your .pro
file, and re-run qmake.
qmake -project
does not try to guess what modules you need in your code.
If you have more than one module, the usual syntax is like:
QT += webkit xml network
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With