如何在Linux中包含Qt库(qwebview.h)?

3

我是一名刚开始使用Qt库的用户。我正在尝试编译我的第一个测试脚本,使用以下头文件:

#include <qwebview.h>

然而它无法编译:
g++ main.cpp -o run.main
main.cpp:2:22: error: qwebview.h: No such file or directory
main.cpp: In function ‘int main()’:
main.cpp:10: error: ‘QWebView’ was not declared in this scope

我在我的Linux Kubuntu机器上安装了这些库:

$ locate qwebview
/usr/include/qt4/Qt/qwebview.h
/usr/include/qt4/QtWebKit/qwebview.h
/usr/lib/qt4/plugins/designer/libqwebview.so

我曾经运行过ldconfig,以确保库被识别,但显然这还不够。

我该如何设置我的机器,以便可以使用Qt开始编译软件?

3个回答

6

在你的 [your_library].pro 文件中添加以下内容:

QT       +=  webkit

那么。
#include <QWebView>

应该足以获得此代码:
QWebView *view = new QWebView(parent);
view->load(QUrl("http://qt.nokia.com/"));

已编译

希望这可以帮助,问候


4

首先,使用正确的大小写来包含:

#include <QWebView>

然后将正确的包含路径添加到编译器中:
g++ -c -I /usr/include/qt4 main.cpp

然后链接相应的库:
g++ -o main.run main.o -lQtCore -lQtGui -lQtWebKit

如果这对您来说太复杂了,尝试使用qmake...

1
#include <QWebView> should work.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接