QtWebKit/QtWebEngine移植差异

原文出处:【wiki.qt.io

This guide gives an overview of the differences between the Qt WebKit and Qt WebEngine APIs in applications.

This intends to provide rough steps to follow when porting an application using Qt WebKit's QWebView API to use Qt WebEngine's QWebEngineView.

Class names

The Qt WebEngine equivalent of Qt WebKit C++ classes are prefixed by QWebEngine instead of QWeb.

Qt WebKit
#include <QWebHistory>
#include <QWebHistoryItem>
#include <QWebPage>
#include <QWebView>
 
QWebHistory
QWebHistoryItem
QWebPage
QWebView
Qt WebEngine
#include <QWebEngineHistory>
#include <QWebEngineHistoryItem>
#include <QWebEnginePage>
#include <QWebEngineView>
 
QWebEngineHistory
QWebEngineHistoryItem
QWebEnginePage
QWebEngineView

Qt module name

In qmake project files

Qt WebKit
QT += webkitwidgets
Qt WebEngine
QT += webenginewidgets

Including the module in source files

Qt WebKit
#include <QtWebKit>
#include <QtWebKitWidgets> // With Qt >= 4.8
Qt WebEngine
#include <QtWebEngineWidgets>

QWebFrame has been merged into QWebEnginePage

It is not possible to access sub-frames. Methods of the main QWebFrame are now available directly through the QWebEnginePage itself.

Qt WebKit
QWebPage page;
connect(page->mainFrame(), SIGNAL (urlChanged(const QUrl&)), SLOT (mySlotName()));
page.mainFrame()->load(url);
Qt WebEngine
QWebEnginePage page;
connect(&page, SIGNAL (urlChanged(const QUrl&)), SLOT (mySlotName()));
page.load(url);

Some methods now return their result asynchronously

Since Qt WebEngine uses a multi-process architecture, the application needs to return to the event loop where the result will be received asynchronously from Qt WebEngine's render process. A function pointer, a functor or a lambda expression must be provided to handle the result when it is available.

Qt WebKit
QWebPage *page = new QWebPage;
QTextEdit *textEdit = new QTextEdit;
// *textEdit is modified immediately.
textEdit->setPlainText(page->toHtml());
textEdit->setPlainText(page->toPlainText());
Qt WebEngine (with a lambda function in C++11)
QWebEnginePage *page = new QWebEnginePage;
QTextEdit *textEdit = new QTextEdit;
// *textEdit must remain valid until the lambda function is called.
page->toHtml([textEdit](const QString &result){ textEdit->setPlainText(result); });
page->toPlainText([textEdit](const QString &result){ textEdit->setPlainText(result); });
Qt WebEngine (with a functor template wrapping a member function)
template<typename Arg, typename R, typename C>
struct InvokeWrapper {
R *receiver;
void (C::*memberFun)(Arg);
void operator()(Arg result) {
(receiver->*memberFun)(result);
}
};
 
template<typename Arg, typename R, typename C>
InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(Arg))
{
InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun};
return wrapper;
}
 
QWebEnginePage *page = new QWebEnginePage;
QTextEdit *textEdit = new QTextEdit;
// *textEdit must remain valid until the functor is called.
page->toHtml(invoke(textEdit, &QTextEdit::setPlainText));
page->toPlainText(invoke(textEdit, &QTextEdit::setPlainText));
Qt WebEngine (with a regular functor)
struct SetPlainTextFunctor {
QTextEdit *textEdit;
SetPlainTextFunctor(QTextEdit *textEdit) : textEdit(textEdit) { }
void operator()(const QString &result) {
textEdit->setPlainText(result);
}
};
 
QWebEnginePage *page = new QWebEnginePage;
QTextEdit *textEdit = new QTextEdit;
// *textEdit must remain valid until the functor is called.
page->toHtml(SetPlainTextFunctor(textEdit));
page->toPlainText(SetPlainTextFunctor(textEdit));

Qt WebEngine does not interact with QNetworkAccessManager

Some classes of Qt Network like QAuthenticator were reused for their interface but, unlike Qt WebKit, Qt WebEngine has its own HTTP implementation and can't go through a QNetworkAccessManager.

Signals and methods of QNetworkAccessManager that are still supported were moved to QWebEnginePage directly.

Qt WebKit
QNetworkAccessManager qnam;
QWebPage page;
page.setNetworkAccessManager(&qnam);
connect(&qnam, SIGNAL (authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT (authenticate(QNetworkReply*,QAuthenticator*)));
Qt WebEngine
QWebEnginePage page;
connect(&page, SIGNAL (authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT (authenticate(QNetworkReply*,QAuthenticator*)));

Notes about individual methods

runJavaScript (QWebEnginePage)

QWebFrame::evaluateJavaScript was renamed and moved to the QWebEnginePage. It is currently only possible to run JavaScript on the main frame of a page and the result is returned asynchronously to the provided functor.

Qt WebKit
QWebPage *page = new QWebPage;
qDebug() << page->mainFrame()->evaluateJavaScript("'Java' + 'Script'");
Qt WebEngine (with lambda expressions in C++11)
QWebEnginePage *page = new QWebEnginePage;
page->runJavaScript("'Java''' 'Script'", [](const QVariant &result){ qDebug() << result; });

setHtml and setContent (QWebEnginePage)

Those methods now perform asynchronously the same way as a normal HTTP load would.

Unavailable Qt WebKit APIs

Qt WebKit classes or methods in this list will not be available in Qt WebEngine.

QGraphicsWebView

Qt WebEngine requires hardware acceleration. Since we couldn't support a web view class in a QGraphicsView unless it is attached to a QGLWidget viewport, this feature is out of scope.

QWebElement

Qt WebEngine uses a multi-process architecture and this means that any access to the internal structure of the page has to be done asynchronously, any query result must be returned through callbacks. The QWebElement API was designed for synchronous access and this would require a complete redesign.

QWebPage::setLinkDelegationPolicy

There is no way to connect a signal to run C++ code when a link is clicked.

QWebDatabase

The Web SQL Database feature that this API was wrapping in QtWebKit was dropped from the HTML5 standard.

QWebPluginDatabase, QWebPluginFactory, QWebPluginInfo, QWebPage::setPalette, QWebView::setRenderHints

Qt WebEngine renders web pages using Skia and isn't using QPainter or Qt for this purpose. The HTML5 standard also now offers much better alternatives that were not available when native controls plugins were introduced in QtWebKit.

QWebHistoryInterface

Visited links are persisted automatically by Qt WebEngine.

QWebPage::setContentEditable

In the latest HTML standard, any document element can be made editable through the contentEditable attribute. So runJavaScript is all that is needed.

page->runJavascript("document.documentElement.contentEditable = true")

QtWebKit/QtWebEngine移植差异(网摘)的更多相关文章

  1. Feedly订阅Blog部落格RSS网摘 - Blog透视镜

    网络信息爆炸的时代,如何更有效率地阅读文章,订阅RSS网摘,可以快速地浏览文章标题,当对某些文章有兴趣时,才点下连结连到原网站,阅读更详细的文章,Feedly Reader阅读器除了提供在线版订阅RS ...

  2. Bloglines订阅Blog部落格RSS网摘 - Blog透视镜

    网络信息蓬勃发展,Blog部落格越来越普及,如果逐一地去浏览网站,势必费时费力,倘若信息可以自己送上门,那就可以节省不少时间,就好像看报纸的标题,有兴趣才点连结,进到网站浏览文章内容,Blogline ...

  3. TCP/IP协议头部结构体(网摘小结)(转)

    源:TCP/IP协议头部结构体(网摘小结) TCP/IP协议头部结构体(转) 网络协议结构体定义 // i386 is little_endian. #ifndef LITTLE_ENDIAN #de ...

  4. Vim命令快捷键(网摘)

    Vim命令快捷键(网摘) 原文出处:[?---->home]

  5. c#与C++类型转换网摘

    转载自 C++和C#转换 https://www.cnblogs.com/zjoch/p/4147182.html c#与C++类型转换,网摘 //c++:HANDLE(void   *)       ...

  6. Delphi 中DataSnap技术网摘

    Delphi2010中DataSnap技术网摘 一.为DataSnap系统服务程序添加描述 这几天一直在研究Delphi 2010的DataSnap,感觉功能真是很强大,现在足有理由证明Delphi7 ...

  7. Python入门及容易!网摘分享给大家!

    Python:Python学习总结 背景 PHP的$和->让人输入的手疼(PHP确实非常简洁和强大,适合WEB编程),Ruby的#.@.@@也好不到哪里(OO人员最该学习的一门语言). Pyth ...

  8. KEIL建立新唐MCU的工程时,移植官网程序报错变量未定义问题解决方法

    最近在使用新唐的MCU,新唐的MCU使用还算方便,你安装好KEIL之后再安装 Nu-Link_Keil_Driver_V3.00.6909 驱动即可建立新唐的MCU工程,注意的是因为新唐MCU是C51 ...

  9. 采访ServiceStack的项目领导Demis Bellot——第1部分(网摘)

    ServiceStack是一个开源的.支持.NET与Mono平台的REST Web Services框架.InfoQ有幸与Demis Bellot深入地讨论了这个项目.在这篇两部分报道的第1部分中,我 ...

随机推荐

  1. PAT-1099(Build A Binary Search Tree)

    题目见这里 分析:分四步进行 1)根据给定的结点情况建二叉树  2)对输入的键值排序(asending) 3)对二叉树中序遍历,同时对应赋key值 4)层次遍历(队列应用) 题目并不困难,但是我误入了 ...

  2. JS运动框架的封装过程(一)

    给大家出一道题,从起点A走到目的地B,一共用了1000毫秒,每一次是30毫秒,请问你在这里面得到了哪些信息? 信息有哪些呢? 第一个,总时长是:1000毫秒 第二个,多久时间走一次?30毫秒 第三个, ...

  3. Scrapy 爬虫实例教程(一)---简介及资源列表

    Scrapy(官网 http://scrapy.org/)是一款功能强大的,用户可定制的网络爬虫软件包.其官方描述称:" Scrapy is a fast high-level screen ...

  4. CentOS升级Python到2.7版本

    查看python的版本 1 python -V Python 2.4.3 1.先安装GCC 1 yum -y install gcc 2.下载Python-2.7.2 1 wget http://py ...

  5. neo4j 数据库导入导出

    工作中需要将 A 图数据库的数据完全导出,并插入到 B 图数据库中.查找资料,好多都是通过导入,导出 CSV 文件来实现.然而,经过仔细研究发现,导出的节点/关系 都带有 id 属性 ,因为 A B ...

  6. man rsync翻译(rsync命令中文手册)

    本文为命令rsync的man文档翻译,几乎所有的选项都翻译了,另外关于筛选规则部分只翻译了一部分.由于原文很多地方都比较啰嗦,所以译文中有些内容可能容易让国人疑惑,所以我个人在某些地方加上了注释.若有 ...

  7. nopCommerce 3.9 大波浪系列 之 网页加载Widgets插件原理

    一.插件简介 插件用于扩展nopCommerce的功能.nopCommerce有几种类型的插件如:支付.税率.配送方式.小部件等(接口如下图),更多插件可以访问nopCommerce官网. 我们看下后 ...

  8. 如何写出面试官欣赏的Java单例

    单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例的特殊类.通过单例模式可以保证系统中一个类只有一个实例. 今天我们不谈单例模式的用途,只说一说如果在面试的时候面试官让你敲一段代码 ...

  9. 有关java 8

    http://www.iteye.com/news/27608     Java 8 发布时间敲定,延期半年 http://www.iteye.com/news/24631/   Java 8 的重要 ...

  10. business meeting

    Metting are all about discussions . discussion expression 开始会议 Let's get started We need to discuss. ...