在 C++ 中使用 WebKit QT 的简单网页浏览器示例代码 [英] Example code for a simple web page browser using WebKit QT in C++

查看:36
本文介绍了在 C++ 中使用 WebKit QT 的简单网页浏览器示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未使用过 QtWebKit,现在需要使用 Qt WebKit 模块 创建一个简单的网页浏览器.我要创建的应用程序需要有一个显示通过命令行传入的网页 URL 的普通窗口.我已经使用 WebKitGTK 完成了这种事情,但我不知道从 Qt 的哪里开始.

I have never used Qt and WebKit and now have a need to create a simple single web page browser using the Qt WebKit module. The application that I'm looking to create needs to have a plain window that displays a web page URL passed in via command line. I've done this sort of thing using WebKitGTK but I have no idea where to start in Qt.

我进行了一些研究以了解所涉及的内容,到目前为止,我只能找到与 WebKit QWebView 类相关的代码片段.

I've done some research to see what is involved and so far I've only been able to find snippets of code that pertain to the WebKit QWebView class.

那么谁能给我提供完整的示例代码,以便在 Qt 中显示一个网页?一旦我完成了那部分,我将能够继续并从那里扩展并继续学习 QtWebKit.

So can anybody provide me with complete sample code that will just display a web page in Qt? Once I get that part down I will be able to continue and extend from there and continue to learn about Qt and WebKit.

我会提供大量的悬赏点数来获得一些出色的帮助.

I will offer up a great deal of bounty points for some excellent help.

推荐答案

您的要求仍然没有足够的范围.如果您想要显示网页的最简单的完整应用程序示例,代码如下:

Your requirement is still not scoped enough. If you want the simplest possible full application example which displays a web page, here is the code:

#include <QtGui>
#include <QtWebKit>

int main(int argc, char** argv) {
    QApplication app(argc, argv);
    QWebView view;
    view.show();
    view.setUrl(QUrl("http://google.com"));
    return app.exec();
}

如果是example.cpp,你可以使用下面的example.pro:

If that is example.cpp, you can use the following example.pro:

QT += webkit
SOURCES = example.cpp

最简单的 Qt 开发方法是使用 Qt Creator,您可以使用 Qt Creator 加载该 .pro 文件,构建应用程序并启动它.只有一个窗口(QWebView 实例),它会打开 Google 主页.

The easiest way to Qt development is using Qt Creator and you can load that .pro file with Qt Creator, build the app, and launch it. There is only one window (QWebView instance) and it will open Google homepage.

这篇关于在 C++ 中使用 WebKit QT 的简单网页浏览器示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆