简体   繁体   English

qmake 生成的 Makefile 中缺少 QtWebKit 依赖项

[英]QtWebKit dependency missing from qmake generated Makefile

I just started working with Qt (in C++), so I followed a "hello, world" example I found online.我刚开始使用 Qt(在 C++ 中),所以我遵循了我在网上找到的“你好,世界”示例。 I created the program hello.cpp in the directory hello:我在 hello 目录中创建了程序 hello.cpp:

#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:我重新运行了三个命令,但是现在运行 make 时出现以下错误:

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我检查了 Makefile 并将 INCPATH 变量定义为

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.它明显缺少 -I/usr/include/qt4/QtWebKit。 The LIBS variable was also missing -lQtWebKit. LIBS 变量也缺少 -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?我需要添加什么才能使 qmake 生成正确的 Makefile?

You need to add:您需要添加:

QT += webkit

to your .pro file, and re-run qmake.到您的.pro文件,然后重新运行 qmake。

qmake -project does not try to guess what modules you need in your code. qmake -project不会尝试猜测您的代码中需要哪些模块。

If you have more than one module, the usual syntax is like:如果您有多个模块,通常的语法如下:

QT += webkit xml network

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM