开发者

QtWebKit dependency missing from qmake generated Makefile

开发者 https://www.devze.com 2023-03-19 01:05 出处:网络
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:

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开发者_如何学C 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
0

精彩评论

暂无评论...
验证码 换一张
取 消