QWebEnginePage 类

QWebEnginePage class provides an object to view and edit web documents. 更多...

Header: #include <QWebEnginePage>
qmake: QT += webenginewidgets
Since: Qt 5.4
继承: QObject

公共类型

enum Feature { Geolocation, MediaAudioCapture, MediaVideoCapture, MediaAudioVideoCapture, ..., DesktopAudioVideoCapture }
enum FileSelectionMode { FileSelectOpen, FileSelectOpenMultiple }
enum FindFlag { FindBackward, FindCaseSensitively }
flags FindFlags
enum JavaScriptConsoleMessageLevel { InfoMessageLevel, WarningMessageLevel, ErrorMessageLevel }
enum NavigationType { NavigationTypeLinkClicked, NavigationTypeTyped, NavigationTypeFormSubmitted, NavigationTypeBackForward, NavigationTypeReload, NavigationTypeOther }
enum PermissionPolicy { PermissionUnknown, PermissionGrantedByUser, PermissionDeniedByUser }
enum RenderProcessTerminationStatus { NormalTerminationStatus, AbnormalTerminationStatus, CrashedTerminationStatus, KilledTerminationStatus }
enum WebAction { NoWebAction, Back, Forward, Stop, ..., InsertUnorderedList }
enum WebWindowType { WebBrowserWindow, WebBrowserTab, WebDialog, WebBrowserBackgroundTab }

特性

公共函数

QWebEnginePage (QObject * parent = Q_NULLPTR)
QWebEnginePage (QWebEngineProfile * profile , QObject * parent = Q_NULLPTR)
virtual ~QWebEnginePage ()
QAction * action (QWebEnginePage::WebAction action ) const
QColor backgroundColor () const
QSizeF contentsSize () const
const QWebEngineContextMenuData & contextMenuData () const
QMenu * createStandardContextMenu ()
QWebEnginePage * devToolsPage () const
void download (const QUrl & url , const QString & filename = QString())
void findText (const QString & subString , QWebEnginePage::FindFlags options = ..., const QWebEngineCallback<bool> & resultCallback = ...)
bool hasSelection () const
QWebEngineHistory * history () const
QIcon icon () const
QUrl iconUrl () const
QWebEnginePage * inspectedPage () const
bool isAudioMuted () const
void load (const QUrl & url )
void load (const QWebEngineHttpRequest & request )
void print (QPrinter * printer , const QWebEngineCallback<bool> & resultCallback )
void printToPdf (const QString & filePath , const QPageLayout & pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()))
void printToPdf (const QWebEngineCallback<const QByteArray &> & resultCallback , const QPageLayout & pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()))
QWebEngineProfile * profile () const
bool recentlyAudible () const
void replaceMisspelledWord (const QString & replacement )
QUrl requestedUrl () const
void runJavaScript (const QString & scriptSource )
void runJavaScript (const QString & scriptSource , quint32 worldId )
void runJavaScript (const QString & scriptSource , const QWebEngineCallback<const QVariant &> & resultCallback )
void runJavaScript (const QString & scriptSource , quint32 worldId , const QWebEngineCallback<const QVariant &> & resultCallback )
void save (const QString & filePath , QWebEngineDownloadItem::SavePageFormat format = QWebEngineDownloadItem::MimeHtmlSaveFormat) const
QWebEngineScriptCollection & scripts ()
QPointF scrollPosition () const
QString selectedText () const
void setAudioMuted (bool muted )
void setBackgroundColor (const QColor & color )
void setContent (const QByteArray & data , const QString & mimeType = QString(), const QUrl & baseUrl = QUrl())
void setDevToolsPage (QWebEnginePage * devToolsPage )
void setFeaturePermission (const QUrl & securityOrigin , QWebEnginePage::Feature feature , QWebEnginePage::PermissionPolicy policy )
void setHtml (const QString & html , const QUrl & baseUrl = QUrl())
void setInspectedPage (QWebEnginePage * page )
void setUrl (const QUrl & url )
void setView (QWidget * view )
void setWebChannel (QWebChannel * channel , uint worldId )
void setWebChannel (QWebChannel * channel )
void setZoomFactor (qreal factor )
QWebEngineSettings * settings () const
QString title () const
void toHtml (const QWebEngineCallback<const QString &> & resultCallback ) const
void toPlainText (const QWebEngineCallback<const QString &> & resultCallback ) const
virtual void triggerAction (QWebEnginePage::WebAction action , bool checked = ...)
QUrl url () const
QWidget * view () const
QWebChannel * webChannel () const
qreal zoomFactor () const

重实现公共函数

virtual bool event (QEvent * e )

信号

void audioMutedChanged (bool muted )
void authenticationRequired (const QUrl & requestUrl , QAuthenticator * authenticator )
void contentsSizeChanged (const QSizeF & size )
void featurePermissionRequestCanceled (const QUrl & securityOrigin , QWebEnginePage::Feature feature )
void featurePermissionRequested (const QUrl & securityOrigin , QWebEnginePage::Feature feature )
void fullScreenRequested (QWebEngineFullScreenRequest fullScreenRequest )
void geometryChangeRequested (const QRect & geom )
void iconChanged (const QIcon & icon )
void iconUrlChanged (const QUrl & url )
void linkHovered (const QString & url )
void loadFinished (bool ok )
void loadProgress (int progress )
void loadStarted ()
void pdfPrintingFinished (const QString & filePath , bool success )
void printRequested ()
void proxyAuthenticationRequired (const QUrl & requestUrl , QAuthenticator * authenticator , const QString & proxyHost )
void quotaRequested (QWebEngineQuotaRequest quotaRequest )
void recentlyAudibleChanged (bool recentlyAudible )
void registerProtocolHandlerRequested (QWebEngineRegisterProtocolHandlerRequest request )
void renderProcessTerminated (QWebEnginePage::RenderProcessTerminationStatus terminationStatus , int exitCode )
void scrollPositionChanged (const QPointF & position )
void selectClientCertificate (QWebEngineClientCertificateSelection clientCertificateSelection )
void selectionChanged ()
void titleChanged (const QString & title )
void urlChanged (const QUrl & url )
void windowCloseRequested ()

静态公共成员

const QMetaObject staticMetaObject

保护函数

virtual bool acceptNavigationRequest (const QUrl & url , QWebEnginePage::NavigationType type , bool isMainFrame )
virtual bool certificateError (const QWebEngineCertificateError & certificateError )
virtual QStringList chooseFiles (QWebEnginePage::FileSelectionMode mode , const QStringList & oldFiles , const QStringList & acceptedMimeTypes )
virtual QWebEnginePage * createWindow (QWebEnginePage::WebWindowType type )
virtual void javaScriptAlert (const QUrl & securityOrigin , const QString & msg )
virtual bool javaScriptConfirm (const QUrl & securityOrigin , const QString & msg )
virtual void javaScriptConsoleMessage (QWebEnginePage::JavaScriptConsoleMessageLevel level , const QString & message , int lineNumber , const QString & sourceID )
virtual bool javaScriptPrompt (const QUrl & securityOrigin , const QString & msg , const QString & defaultValue , QString * result )

额外继承成员

详细描述

QWebEnginePage class provides an object to view and edit web documents.

A Web 引擎页面 保持 HTML 文档的内容、导航链接的历史及动作。

QWebEnginePage 's API is very similar to QWebEngineView ,仍提供常用功能像 action () (known as pageAction () in QWebEngineView ), triggerAction (),和 findText ().

页面可以被加载使用 load () 或 setUrl ()。另外,若拥有随时可用的 HTML 内容,可以使用 setHtml ()。GET 方法始终被用于加载 URL。

QWebEnginePage class also offers methods to retrieve both the URL currently loaded by the page (see url ()) 及要被加载的原始请求 URL (见 requestedUrl ))。这些方法使在加载进程期间发生 DNS 解答 (或重定向) 前后检索 URL 成为可能。 requestedUrl () 还匹配被添加到页面历史的 URL ( QWebEngineHistory ) 若加载成功。

HTML 页面标题可以被访问采用 title () 特性。此外,页面还可以指定图标,其可以被访问使用 icon () 或其 URL 使用 iconUrl () 特性。若标题或图标改变,相应 titleChanged (), iconChanged () 和 iconUrlChanged () 信号会被发射。 zoomFactor () 特性使能够按比例因子缩放网页内容。

loadStarted () 信号被发射,当页面开始加载时,而 loadProgress () 信号被发射,每当网页元素 (如嵌入图像或脚本) 完成加载时。 loadFinished () 信号被发射,当页面内容已加载完成时 (独立于脚本执行或页面渲染)。其自变量,是 true or false ,指示加载操作是否成功。

HTML 文档被加载于 main frame 在网页中。若它引用 child frames (定义通过 <frame> or <iframe> 元素),它们被认为是内容的一部分。子级框架只可透过 JavaScript 单独访问。

网站定义 security origin 为客户端侧脚本 (或数据库) 安全访问彼此资源。来源由主机名、方案及端口号构成。例如站点 http://www.example.com/my/page.html and http://www.example.com/my/overview.html 允许共享同一数据库或访问彼此的文档,当用于 HTML 框架集和 JavaScript 时。同时, http://www.malicious.com/evil.html 被阻止访问其下资源为 http://www.example.com/ , because they are of a different security origin. By default, local schemes like file:// and qrc:// 被认为是在同一安全来源中,且可以访问彼此资源。默认情况下,本地资源被限制访问远程内容,这意味着 file:// 将不能访问 http://domain.com/foo.html .

脚本可以被执行在网页通过使用 runJavaScript (),在主 JavaScript world ,来自 web 内容的其它 JavaScript,或在它们自己的独立世界。虽然页面的 DOM 可以被访问从任何世界,但在某一世界中定义的 JavaScript 函数变量是不能从另一世界访问的。 QWebEngineScript::ScriptWorldId 为此目的提供了一些预定义 ID。使用 runJavaScript() 在世界 ID 外版本如同运行脚本在 MainWorld .

FocusOnNavigationEnabled 设置可以被用于使查看关联页面自动接收聚焦,当发生导航操作时 (像加载或重新加载页面或透过历史进行导航)。

成员类型文档编制

enum QWebEnginePage:: Feature

此枚举描述用户可能被要求授予 (或拒绝) 访问的平台特征访问类别:

常量 描述
QWebEnginePage::Geolocation 1 Location hardware or service.
QWebEnginePage::MediaAudioCapture 2 Audio capture devices, such as microphones.
QWebEnginePage::MediaVideoCapture 3 Video devices, such as cameras.
QWebEnginePage::MediaAudioVideoCapture 4 Both audio and video capture devices.
QWebEnginePage::MouseLock 5 Mouse locking, which locks the mouse pointer to the web view and is typically used in games.
QWebEnginePage::DesktopVideoCapture 6 Video output capture, that is, the capture of the user's display, for screen sharing purposes for example. (Added in Qt 5.10)
QWebEnginePage::DesktopAudioVideoCapture 7 Both audio and video output capture. (Added in Qt 5.10)

另请参阅 featurePermissionRequested (), featurePermissionRequestCanceled (), setFeaturePermission (),和 PermissionPolicy .

enum QWebEnginePage:: FileSelectionMode

This enum indicates whether the implementation of the chooseFiles () function should return only one file or may return multiple files:

常量 描述
QWebEnginePage::FileSelectOpen 0 只返回一个文件名。
QWebEnginePage::FileSelectOpenMultiple 1 返回多个文件名。

另请参阅 chooseFiles ().

enum QWebEnginePage:: FindFlag
flags QWebEnginePage:: FindFlags

This enum describes the options available to the findText () function. The options can be OR-ed together from the following list:

常量 描述
QWebEnginePage::FindBackward 1 向后搜索,而不是向前。
QWebEnginePage::FindCaseSensitively 2 By default findText () works case insensitive. Specifying this option changes the behavior to a case sensitive find operation.

The FindFlags type is a typedef for QFlags <FindFlag>. It stores an OR combination of FindFlag values.

enum QWebEnginePage:: JavaScriptConsoleMessageLevel

此枚举描述了 JavaScript 控制台消息,可以拥有的不同严重级别:

常量 描述
QWebEnginePage::InfoMessageLevel 0 消息为纯情报且可以被安全忽略。
QWebEnginePage::WarningMessageLevel 1 消息告知可能需要关注的意外行为 (或错误)。
QWebEnginePage::ErrorMessageLevel 2 消息指示出现错误。

此枚举描述导航请求类型:

常量 描述
QWebEnginePage::NavigationTypeLinkClicked 0 导航请求由点击链接产生。
QWebEnginePage::NavigationTypeTyped 1 导航请求由明确加载 URL 产生。
QWebEnginePage::NavigationTypeFormSubmitted 2 导航请求由表单提交产生。
QWebEnginePage::NavigationTypeBackForward 3 导航请求由后退或前进动作产生。
QWebEnginePage::NavigationTypeReload 4 导航请求由重新加载动作产生。
QWebEnginePage::NavigationTypeOther 5 导航请求由上述未涵盖的其它手段触发。

另请参阅 acceptNavigationRequest ().

enum QWebEnginePage:: PermissionPolicy

This enum describes the permission policies that the user may set for data or device access:

常量 描述
QWebEnginePage::PermissionUnknown 0 用户是否授予或拒绝权限未知。
QWebEnginePage::PermissionGrantedByUser 1 用户已授予权限。
QWebEnginePage::PermissionDeniedByUser 2 用户已拒绝权限。

另请参阅 featurePermissionRequested (), featurePermissionRequestCanceled (), setFeaturePermission (),和 Feature .

enum QWebEnginePage:: RenderProcessTerminationStatus

此枚举描述渲染进程终止状态:

常量 描述
QWebEnginePage::NormalTerminationStatus 0 渲染进程正常终止。
QWebEnginePage::AbnormalTerminationStatus 1 渲染进程以非零退出状态终止。
QWebEnginePage::CrashedTerminationStatus 2 渲染进程崩溃 (例如:由于分段故障)。
QWebEnginePage::KilledTerminationStatus 3 渲染进程被杀除,例如被 SIGKILL 或被任务管理器杀除。

This enum was introduced or modified in Qt 5.6.

enum QWebEnginePage:: WebAction

此枚举描述可以在网页上履行的动作类型。

动作才有效,当可应用时。

动作的可用性可以被确定,通过检查 isEnabled() 在返回动作通过 action ().

常量 描述
QWebEnginePage::NoWebAction - 1 没有动作被触发。
QWebEnginePage::Back 0 在导航链接历史中后退导航。
QWebEnginePage::Forward 1 在导航链接历史中前进导航。
QWebEnginePage::Stop 2 停止加载当前页面。
QWebEnginePage::Reload 3 重新加载当前页面。
QWebEnginePage::ReloadAndBypassCache 10 重新加载当前页面,但不使用任何本地缓存。
QWebEnginePage::Cut 4 把目前选中内容剪切到剪贴板。
QWebEnginePage::Copy 5 把目前选中内容拷贝到剪贴板。
QWebEnginePage::Paste 6 从剪贴板粘贴内容。
QWebEnginePage::Undo 7 撤消上一编辑动作。
QWebEnginePage::Redo 8 重做上一编辑动作。
QWebEnginePage::SelectAll 9 选择所有内容。仅当页面内容被聚焦时此动作才启用。聚焦可以被强制通过 JavaScript window.focus() 调用,或 FocusOnNavigationEnabled 设置应该被启用以获得自动聚焦。
QWebEnginePage::PasteAndMatchStyle 11 采用当前样式从剪贴板粘贴内容。
QWebEnginePage::OpenLinkInThisWindow 12 在当前窗口中打开当前链接。(在 Qt 5.6 添加)
QWebEnginePage::OpenLinkInNewWindow 13 在新窗口中打开当前链接。要求实现 createWindow ()。(在 Qt 5.6 添加)
QWebEnginePage::OpenLinkInNewTab 14 在新选项卡中打开当前链接。要求实现 createWindow ()。(在 Qt 5.6 添加)
QWebEnginePage::OpenLinkInNewBackgroundTab 31 在新背景选项卡中打开当前链接。要求实现 createWindow ()。(在 Qt 5.7 添加)
QWebEnginePage::CopyLinkToClipboard 15 把当前链接拷贝到剪贴板。(在 Qt 5.6 添加)
QWebEnginePage::CopyImageToClipboard 17 把被点击图像拷贝到剪贴板。(在 Qt 5.6 添加)
QWebEnginePage::CopyImageUrlToClipboard 18 把被点击图像的 URL 拷贝到剪贴板。(在 Qt 5.6 添加)
QWebEnginePage::CopyMediaUrlToClipboard 20 把悬停音频或视频的 URL 拷贝到剪贴板。(在 Qt 5.6 添加)
QWebEnginePage::ToggleMediaControls 21 Toggle between showing and hiding the controls for the hovered audio or video element. (Added in Qt 5.6)
QWebEnginePage::ToggleMediaLoop 22 Toggle whether the hovered audio or video should loop on completetion or not. (Added in Qt 5.6)
QWebEnginePage::ToggleMediaPlayPause 23 Toggle the play/pause state of the hovered audio or video element. (Added in Qt 5.6)
QWebEnginePage::ToggleMediaMute 24 静音或取消静音悬停的音频或视频元素。(在 Qt 5.6 添加)
QWebEnginePage::DownloadLinkToDisk 16 把当前链接下载到磁盘。要求槽为 downloadRequested() 。(在 Qt 5.6 添加)
QWebEnginePage::DownloadImageToDisk 19 把被突显图像下载到磁盘。要求槽为 downloadRequested() 。(在 Qt 5.6 添加)
QWebEnginePage::DownloadMediaToDisk 25 Download the hovered audio or video to the disk. Requires a slot for downloadRequested() 。(在 Qt 5.6 添加)
QWebEnginePage::InspectElement 26 Trigger any attached Web Inspector to inspect the highlighed element. (Added in Qt 5.6)
QWebEnginePage::ExitFullScreen 27 退出全屏模式。(在 Qt 5.6 添加)
QWebEnginePage::RequestClose 28 请求关闭网页。若定义, window.onbeforeunload handler is run, and the user can confirm or reject to close the page. If the close request is confirmed, windowCloseRequested is emitted. (Added in Qt 5.6)
QWebEnginePage::Unselect 29 清零当前选定。(在 Qt 5.7 添加)
QWebEnginePage::SavePage 30 把当前页面保存到磁盘。MHTML 是用于把网页存储在磁盘的默认格式。要求槽为 downloadRequested() 。(在 Qt 5.7 添加)
QWebEnginePage::ViewSource 32 Show the source of the current page in a new tab. Requires implementation of createWindow ()。(在 Qt 5.8 添加)
QWebEnginePage::ToggleBold 33 Toggles boldness for the selection or at the cursor position. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::ToggleItalic 34 Toggles italics for the selection or at the cursor position. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::ToggleUnderline 35 Toggles underlining of the selection or at the cursor position. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::ToggleStrikethrough 36 Toggles striking through the selection or at the cursor position. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::AlignLeft 37 Aligns the lines containing the selection or the cursor to the left. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::AlignCenter 38 Aligns the lines containing the selection or the cursor at the center. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::AlignRight 39 Aligns the lines containing the selection or the cursor to the right. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::AlignJustified 40 Stretches the lines containing the selection or the cursor so that each line has equal width. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::Indent 41 缩进包含选定或光标的行。要求 contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::Outdent 42 伸出包含选定或光标的行。要求 contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::InsertOrderedList 43 Inserts an ordered list at the current cursor position, deleting the current selection. Requires contenteditable="true" 。(在 Qt 5.10 添加)
QWebEnginePage::InsertUnorderedList 44 Inserts an unordered list at the current cursor position, deleting the current selection. Requires contenteditable="true" 。(在 Qt 5.10 添加)

enum QWebEnginePage:: WebWindowType

This enum describes the types of window that can be created by the createWindow () 函数:

常量 描述
QWebEnginePage::WebBrowserWindow 0 完整 Web 浏览器窗口。
QWebEnginePage::WebBrowserTab 1 Web 浏览器选项卡。
QWebEnginePage::WebDialog 2 没有装饰的窗口。
QWebEnginePage::WebBrowserBackgroundTab 3 A web browser tab without hiding the current visible WebEngineView 。(在 Qt 5.7 添加)

特性文档编制

audioMuted : bool

This property holds whether the current page audio is muted.

默认值为 false .

This property was introduced in Qt 5.7.

访问函数:

bool isAudioMuted () const
void setAudioMuted (bool muted )

通知信号:

void audioMutedChanged (bool muted )

另请参阅 recentlyAudible .

backgroundColor : QColor

This property holds the page's background color behind the document's body.

You can set the background color to Qt::transparent or to a translucent color to see through the document, or you can set it to match your web content in a hybrid application to prevent the white flashes that may appear during loading.

默认值为白色。

This property was introduced in Qt 5.6.

访问函数:

QColor backgroundColor () const
void setBackgroundColor (const QColor & color )

contentsSize : const QSizeF

此特性保持页面内容的尺寸。

This property was introduced in Qt 5.7.

访问函数:

QSizeF contentsSize () const

通知信号:

void contentsSizeChanged (const QSizeF & size )

hasSelection : const bool

This property holds whether this page contains selected content or not.

访问函数:

bool hasSelection () const

另请参阅 selectionChanged ().

icon : const QIcon

此特性保持关联目前查看页面的图标。

By default, this property contains a null icon. If the web page specifies more than one icon, the icon property encapsulates the available candidate icons in a single, scalable QIcon .

This property was introduced in Qt 5.7.

访问函数:

QIcon icon () const

通知信号:

void iconChanged (const QIcon & icon )

另请参阅 iconChanged (), iconUrl (),和 iconUrlChanged ().

iconUrl : const QUrl

此特性保持关联目前查看页面的图标 URL。

默认情况下,此特性包含空 URL。

访问函数:

QUrl iconUrl () const

通知信号:

void iconUrlChanged (const QUrl & url )

另请参阅 iconUrlChanged (), icon (),和 iconChanged ().

recentlyAudible : const bool

This property holds the current page's audible state , that is, whether audio was recently played or not.

默认值为 false .

This property was introduced in Qt 5.7.

访问函数:

bool recentlyAudible () const

通知信号:

void recentlyAudibleChanged (bool recentlyAudible )

另请参阅 audioMuted .

requestedUrl : const QUrl

This property holds the URL that was originally requested to be loaded by the page that is currently viewed.

注意: The URL may differ from the one returned by url (), which is the actual URL that results from DNS resolution or redirection.

访问函数:

QUrl requestedUrl () const

另请参阅 url () 和 setUrl ().

scrollPosition : const QPointF

此特性保持页面内容的卷动位置。

This property was introduced in Qt 5.7.

访问函数:

QPointF scrollPosition () const

通知信号:

void scrollPositionChanged (const QPointF & position )

selectedText : const QString

此特性保持当前选中的文本。

默认情况下,此特性包含空字符串。

访问函数:

QString selectedText () const

另请参阅 selectionChanged ().

title : const QString

此特性保持页面的标题,定义通过 HTML <title> 元素。

若页面没有 <title> 元素,则使用 URL 代替。对于 file:// URL,仅使用文件名,而非完整路径。

默认情况下,在任何内容被加载之前,此特性包含空字符串。

访问函数:

QString title () const

另请参阅 titleChanged ().

url : QUrl

此特性保持目前查看页面的 URL。

设置此特性清零视图并加载 URL。

默认情况下,此特性包含空的无效 URL。

访问函数:

QUrl url () const
void setUrl (const QUrl & url )

另请参阅 urlChanged ().

zoomFactor : qreal

此特性保持页面内容的缩放因子。

有效值范围从 0.25 to 5.0 。默认因子为 1.0 .

访问函数:

qreal zoomFactor () const
void setZoomFactor (qreal factor )

成员函数文档编制

void QWebEnginePage:: runJavaScript (const QString & scriptSource , quint32 worldId , const QWebEngineCallback <const QVariant &> & resultCallback )

void QWebEnginePage:: runJavaScript (const QString & scriptSource , quint32 worldId )

void QWebEnginePage:: runJavaScript (const QString & scriptSource )

void QWebEnginePage:: runJavaScript (const QString & scriptSource , const QWebEngineCallback <const QVariant &> & resultCallback )

运行包含的 JavaScript 代码在 scriptSource 无需校验页面 DOM 是否已被构建。若需要脚本如何运行的更多地控制,请考虑使用 scripts () 代替。

To avoid conflicts with other scripts executed on the page, the world in which the script is run is specified by worldId . The world ID values are the same as provided by QWebEngineScript::ScriptWorldId , and between 0 and 256 . If you leave out the world ID, the script is run in the MainWorld .

When the script has been executed, resultCallback is called with the result of the last executed statement. resultCallback 可以是函数指针、函子或 Lambda,且期望接受 QVariant parameter. For example:

page.runJavaScript("document.title", [](const QVariant &v) { qDebug() << v.toString(); });
							

Only plain data can be returned from JavaScript as the result value. Supported data types include all of the JSON data types as well as, for example, Date and ArrayBuffer . Unsupported data types include, for example, 函数 and Promise .

警告: Do not execute lengthy routines in the callback function, because it might block the rendering of the web engine page.

警告: 我们保证回调 ( resultCallback ) 总是被调用,但它可能在页面销毁期间完成。当 QWebEnginePage 被删除,会采用无效值触发回调,因此它是不安全的,去使用相应 QWebEnginePage or QWebEngineView 实例在其中。

This documentation was introduced in Qt 5.7.

另请参阅 scripts (), QWebEngineScript::ScriptWorldId ,和 脚本注入 .

QWebEnginePage:: QWebEnginePage ( QObject * parent = Q_NULLPTR)

构造空 QWebEnginePage with the parent parent .

QWebEnginePage:: QWebEnginePage ( QWebEngineProfile * profile , QObject * parent = Q_NULLPTR)

Constructs an empty web engine page in the web engine profile profile with the parent parent .

If the profile is not the default profile, the caller must ensure that the profile stays alive for as long as the page does.

This function was introduced in Qt 5.5.

[virtual] QWebEnginePage:: ~QWebEnginePage ()

销毁 Web 页面。

[virtual protected] bool QWebEnginePage:: acceptNavigationRequest (const QUrl & url , QWebEnginePage::NavigationType type , bool isMainFrame )

此函数被调用在接收请求以导航到指定 url 通过指定导航类型 type . isMainFrame 指示请求对应主框架或子级框架。若函数返回 true ,导航请求被接受且 url 被加载。默认实现接受所有导航请求。

此函数被调用为绝对 URL 前缀采用 http:// or https:// 及为无法识别方案,譬如 mailto: ,其会被处理通过 QDesktopServices 若接受。要在接收请求导航到本地 URL 时也调用此函数,URL 前缀采用 http:// .

导航请求可以被委托给 Qt 应用程序,而不是让 HTML 处理程序引擎通过重载此函数处理它们。这是必要的,当把 HTML 文档用作用户界面的一部分,且不显示外部数据时 (例如:当显示结果列表时)。

注意: 加载进程开始且 loadStarted () 信号被发射 before 请求被接受或拒绝。因此, loadFinished () 信号返回 false 是可预期的即使在委派请求后。

QWebEngineUrlRequestInterceptor 类提供用于拦截和操纵请求的进一步选项。

This function was introduced in Qt 5.5.

QAction *QWebEnginePage:: action ( QWebEnginePage::WebAction action ) const

返回 QAction 为指定 WebAction action .

动作归 QWebEnginePage 但可以通过改变其特性定制外观。

QWebEnginePage 还负责实现动作,以便触发时在页面履行相应动作。

另请参阅 triggerAction ().

[signal] void QWebEnginePage:: audioMutedChanged ( bool muted )

This signal is emitted when the page's muted state changes.

注意: Not to be confused with a specific HTML5 audio or video element being muted.

This function was introduced in Qt 5.7.

注意: 通知信号为特性 audioMuted .

[signal] void QWebEnginePage:: authenticationRequired (const QUrl & requestUrl , QAuthenticator * authenticator )

此信号被发射当访问 requestUrl 要求身份验证。 authenticator 应该被用于传递连接的用户名和口令。

[virtual protected] bool QWebEnginePage:: certificateError (const QWebEngineCertificateError & certificateError )

此函数被调用,当加载给定请求时引发无效证书错误。

certificateError 参数包含证书和错误细节的有关信息。

返回 true 忽略错误并完成请求。返回 false 停止加载请求。

另请参阅 QWebEngineCertificateError .

[virtual protected] QStringList QWebEnginePage:: chooseFiles ( QWebEnginePage::FileSelectionMode mode , const QStringList & oldFiles , const QStringList & acceptedMimeTypes )

This function is called when the web content requests a file name, for example as a result of the user clicking on a file upload button in an HTML form.

mode indicates whether only one file or multiple files are expected to be returned.

A suggested filename may be provided as the first entry of oldFiles . acceptedMimeTypes is ignored by the default implementation, but might be used by overrides.

const QWebEngineContextMenuData &QWebEnginePage:: contextMenuData () const

返回当前上下文菜单的有关额外数据。它仅保证是有效的在调用 QWebEngineView::contextMenuEvent () 处理程序的关联 QWebEngineView .

This function was introduced in Qt 5.7.

另请参阅 createStandardContextMenu ().

QMenu *QWebEnginePage:: createStandardContextMenu ()

创建标准上下文菜单,当用户采用鼠标右键点击网页时展示。它被调用从默认 contextMenuEvent() 处理程序。弹出菜单的所有权被转移给调用者。

返回 nullptr 若上下文菜单数据未被初始化,例如:在实际不请求上下文菜单时调用它。

[virtual protected] QWebEnginePage *QWebEnginePage:: createWindow ( QWebEnginePage::WebWindowType type )

此函数被调用以创建新窗口,采用指定 type 。例如,当 JavaScript 程序请求在新窗口中打开文档时。

若新窗口可以被创建,新窗口的 QWebEnginePage 被返回;否则 null 指针被返回。

若网页关联视图为 QWebEngineView 对象,则默认实现把请求转发给 QWebEngineView::createWindow ();否则它返回 null 指针。

注意: 在通过 JavaScript 触发创建窗口的情况中,除重实现此方法外,应用程序还必须设置 QWebEngineSettings::JavascriptCanOpenWindows to true in order for the method to get called.

另请参阅 QWebEngineView::createWindow ().

QWebEnginePage *QWebEnginePage:: devToolsPage () const

返回托管此页面开发者工具的页面,若有的话。

返回 nullptr 若未设置开发者工具页面。

This function was introduced in Qt 5.11.

另请参阅 setDevToolsPage () 和 inspectedPage ().

void QWebEnginePage:: download (const QUrl & url , const QString & filename = QString())

下载来自定位的资源,给定通过 url 到本地文件。

filename 被给定,它会被用作建议文件名。若它是相对的,则采用给定名称把文件保存在标准下载定位。若它是 null 或空 QString ,使用默认文件名。

这会发射 QWebEngineProfile::downloadRequested (),在下载开始后。

This function was introduced in Qt 5.10.

[virtual] bool QWebEnginePage:: event ( QEvent * e )

Reimplemented from QObject::event ().

[signal] void QWebEnginePage:: featurePermissionRequestCanceled (const QUrl & securityOrigin , QWebEnginePage::Feature feature )

此信号被发射当网站被标识,通过 securityOrigin 取消先前发出的请求,为使用 feature .

另请参阅 featurePermissionRequested () 和 setFeaturePermission ().

[signal] void QWebEnginePage:: featurePermissionRequested (const QUrl & securityOrigin , QWebEnginePage::Feature feature )

此信号被发射当网站被标识,通过 securityOrigin requests to make use of the resource or device identified by feature .

另请参阅 featurePermissionRequestCanceled () 和 setFeaturePermission ().

void QWebEnginePage:: findText (const QString & subString , QWebEnginePage::FindFlags options = ..., const QWebEngineCallback < bool > & resultCallback = ...)

查找指定字符串, subString , in the page, using the given options .

To clear the search highlight, just pass an empty string.

resultCallback must take a boolean parameter. It will be called with a value of true subString was found; otherwise the callback value will be false .

警告: 我们保证回调 ( resultCallback ) 总是被调用,但它可能在页面销毁期间完成。当 QWebEnginePage 被删除,会采用无效值触发回调,因此它是不安全的,去使用相应 QWebEnginePage or QWebEngineView 实例在其中。

例如:

    m_view->page()->findText(QStringLiteral("Qt"), QWebEnginePage::FindFlags(), [this](bool found) {
        if (!found) QMessageBox::information(m_view, QString(), QStringLiteral("No occurrences found"));
    });
							

[signal] void QWebEnginePage:: fullScreenRequested ( QWebEngineFullScreenRequest fullScreenRequest )

This signal is emitted when the web page issues the request to enter fullscreen mode for a web-element, usually a video element.

请求对象 fullScreenRequest 可用于接受或拒绝请求。

If the request is accepted the element requesting fullscreen will fill the viewport, but it is up to the application to make the view fullscreen or move the page to a view that is fullscreen.

另请参阅 QWebEngineSettings::FullScreenSupportEnabled .

[signal] void QWebEnginePage:: geometryChangeRequested (const QRect & geom )

此信号被发射每当文档希望把页面位置和大小更改为 geom 。这会发生,例如透过 JavaScript。

注意: setGeometry() 期望尺寸排除窗口装饰,而 geom 包括。必须移除框架边距尺寸从 geom 以正确处理此信号。

window->setGeometry(geom.marginsRemoved(window->frameMargins()));
							

QWebEngineHistory *QWebEnginePage:: history () const

返回指向导航网页的视图历史的指针。

[signal] void QWebEnginePage:: iconChanged (const QIcon & icon )

此信号被发射当页面关联的 Favicon 图标被改变时。新图标被指定由 icon .

This function was introduced in Qt 5.7.

注意: 通知信号为特性 icon .

另请参阅 icon (), iconUrl (),和 iconUrlChanged ().

[signal] void QWebEnginePage:: iconUrlChanged (const QUrl & url )

此信号被发射当页面关联的 Favicon 图标 URL 被改变时。新图标 URL 被指定由 url .

注意: 通知信号为特性 iconUrl .

另请参阅 iconUrl (), icon (),和 iconChanged ().

QWebEnginePage *QWebEnginePage:: inspectedPage () const

返回此页面正在审查的页面,若有的话。

返回 nullptr 如果此页面不是开发者工具页面。

This function was introduced in Qt 5.11.

另请参阅 setInspectedPage () 和 devToolsPage ().

[virtual protected] void QWebEnginePage:: javaScriptAlert (const QUrl & securityOrigin , const QString & msg )

此函数被调用,每当 JavaScript 程序运行在附属框架采用 securityOrigin 调用 alert() 函数采用消息 msg .

默认实现展示消息, msg , with QMessageBox::information .

[virtual protected] bool QWebEnginePage:: javaScriptConfirm (const QUrl & securityOrigin , const QString & msg )

此函数被调用,每当 JavaScript 程序运行在附属框架采用 securityOrigin 调用 confirm() 函数采用消息 msg 。返回 true if the user confirms the message; otherwise returns false .

It is also called when the onbeforeunload handler is requesting a confirmation before leaving a page.

The default implementation executes the query using QMessageBox::information with QMessageBox::Ok and QMessageBox::Cancel buttons.

[virtual protected] void QWebEnginePage:: javaScriptConsoleMessage ( QWebEnginePage::JavaScriptConsoleMessageLevel level , const QString & message , int lineNumber , const QString & sourceID )

This function is called when a JavaScript program tries to print the message to the web browser's console.

For example, in case of evaluation errors the source URL may be provided in sourceID as well as the lineNumber .

level indicates the severity of the event that triggered the message. That is, whether it was triggered by an error or a less severe event.

Since Qt 5.6, the default implementation logs the messages in a js 日志类别 .

另请参阅 控制台日志 .

[virtual protected] bool QWebEnginePage:: javaScriptPrompt (const QUrl & securityOrigin , const QString & msg , const QString & defaultValue , QString * result )

此函数被调用,每当 JavaScript 程序运行在附属框架采用 securityOrigin tries to prompt the user for input. The program may provide an optional message, msg , as well as a default value for the input in defaultValue .

If the prompt was cancelled by the user, the implementation should return false ; otherwise the result should be written to result and true should be returned. If the prompt was not cancelled by the user, the implementation should return true and the result string must not be null.

默认实现使用 QInputDialog::getText ().

[signal] void QWebEnginePage:: linkHovered (const QString & url )

此信号被发射当鼠标悬停链接上时。 url 包含链接的目标 URL。

void QWebEnginePage:: load (const QUrl & url )

加载 url 进此页面。

注意: 视图保持不变,直到已达成足够数据才显示新的 URL。

另请参阅 setUrl (), setHtml (),和 setContent ().

void QWebEnginePage:: load (const QWebEngineHttpRequest & request )

发出指定 request 并加载响应。

This function was introduced in Qt 5.9.

另请参阅 load (), setUrl (), url (), urlChanged (),和 QUrl::fromUserInput ().

[signal] void QWebEnginePage:: loadFinished ( bool ok )

此信号被发射当页面内容加载完成时。此信号独立于脚本执行 (或页面渲染)。 ok 将指示加载是否成功 (或发生任何错误)。

注意: 导航请求可以委托给 Qt 应用程序,而不是让 HTML 处理程序引擎处理它们,通过重载 acceptNavigationRequest () 函数。因为加载过程已开始,且 loadStarted () 信号被发射 before 请求被接受或拒绝, loadFinished() 信号返回 false 是可预期的即使在委派请求后。

另请参阅 loadStarted () 和 acceptNavigationRequest ().

[signal] void QWebEnginePage:: loadProgress ( int progress )

此信号被发射当全局进度状态改变时。当前值被提供由 progress 并缩放到 0 - 100,其是默认范围为 QProgressBar 。它累计所有子级帧的变化。

[signal] void QWebEnginePage:: loadStarted ()

此信号被发射当页面开始加载内容。

另请参阅 loadFinished () 和 acceptNavigationRequest ().

[signal] void QWebEnginePage:: pdfPrintingFinished (const QString & filePath , bool success )

此信号被发射当把网页打印成 PDF 文件已完成时。 filePath will contain the path the file was requested to be created at, and success will be true if the file was successfully created and false 否则。

This function was introduced in Qt 5.9.

另请参阅 printToPdf ().

void QWebEnginePage:: print ( QPrinter * printer , const QWebEngineCallback < bool > & resultCallback )

Renders the current content of the page into a temporary PDF document, then prints it using printer .

The settings for creating and printing the PDF document will be retrieved from the printer object. It is the users responsibility to ensure the printer remains valid until resultCallback has been called.

注意: The rendering of the current content into a temporary PDF document is asynchronous and does not block the main thread. However, the subsequent rendering of PDF into printer runs on the main thread and will therefore block the event loop. Moreover, printing runs on the browser process, which is by default not sandboxed.

resultCallback must take a boolean as parameter. If printing was successful, this boolean will have the value true , otherwise, its value will be false .

警告: 我们保证回调 ( resultCallback ) 总是被调用,但它可能在页面销毁期间完成。当 QWebEnginePage 被删除,会采用无效值触发回调,因此它是不安全的,去使用相应 QWebEnginePage or QWebEngineView 实例在其中。

This function was introduced in Qt 5.8.

[signal] void QWebEnginePage:: printRequested ()

此信号被发射当 JavaScript window.print() 方法被调用。通常,信号处理程序可以简单调用 printToPdf ().

This function was introduced in Qt 5.12.

另请参阅 printToPdf ().

void QWebEnginePage:: printToPdf (const QString & filePath , const QPageLayout & pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()))

Renders the current content of the page into a PDF document and saves it in the location specified in filePath . The page size and orientation of the produced PDF document are taken from the values specified in pageLayout .

This method issues an asynchronous request for printing the web page into a PDF and returns immediately. To be informed about the result of the request, connect to the signal pdfPrintingFinished ().

If a file already exists at the provided file path, it will be overwritten.

This function was introduced in Qt 5.7.

另请参阅 pdfPrintingFinished ().

void QWebEnginePage:: printToPdf (const QWebEngineCallback <const QByteArray &> & resultCallback , const QPageLayout & pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()))

Renders the current content of the page into a PDF document and returns a byte array containing the PDF data as parameter to resultCallback . The page size and orientation of the produced PDF document are taken from the values specified in pageLayout .

resultCallback must take a const reference to a QByteArray as parameter. If printing was successful, this byte array will contain the PDF data, otherwise, the byte array will be empty.

警告: 我们保证回调 ( resultCallback ) 总是被调用,但它可能在页面销毁期间完成。当 QWebEnginePage 被删除,会采用无效值触发回调,因此它是不安全的,去使用相应 QWebEnginePage or QWebEngineView 实例在其中。

This function was introduced in Qt 5.7.

QWebEngineProfile *QWebEnginePage:: profile () const

返回页面所属 Web 引擎配置文件。

This function was introduced in Qt 5.5.

[signal] void QWebEnginePage:: proxyAuthenticationRequired (const QUrl & requestUrl , QAuthenticator * authenticator , const QString & proxyHost )

此信号被发射当访问 requestUrl via proxyHost 要求对代理进行身份验证。 authenticator 应该被用于传递连接的用户名和口令。

[signal] void QWebEnginePage:: quotaRequested ( QWebEngineQuotaRequest quotaRequest )

此信号被发射当网页请求的持久性存储大于应用程序在文件系统 API 中的当前分配时。默认配额为 0 字节。

请求对象 quotaRequest 可用于接受或拒绝请求。

This function was introduced in Qt 5.11.

[signal] void QWebEnginePage:: recentlyAudibleChanged ( bool recentlyAudible )

此信号会被发射,当页面的可听见状态, recentlyAudible 改变,因为音频播放或停止。

注意: 信号也会被发射当调用 setAudioMuted () method. Also, if the audio is paused, this signal is emitted with an approximate two-second delay , from the moment the audio is paused.

This function was introduced in Qt 5.7.

注意: 通知信号为特性 recentlyAudible .

[signal] void QWebEnginePage:: registerProtocolHandlerRequested ( QWebEngineRegisterProtocolHandlerRequest request )

此信号被发射当网页尝试注册自定义协议,使用 registerProtocolHandler API.

请求对象 request 可用于接受或拒绝请求:

void WebPage::handleRegisterProtocolHandlerRequested(QWebEngineRegisterProtocolHandlerRequest request)
{
    auto answer = QMessageBox::question(
        view()->window(),
        tr("Permission Request"),
        tr("Allow %1 to open all %2 links?")
        .arg(request.origin().host())
        .arg(request.scheme()));
    if (answer == QMessageBox::Yes)
        request.accept();
    else
        request.reject();
}
							

This function was introduced in Qt 5.11.

[signal] void QWebEnginePage:: renderProcessTerminated ( QWebEnginePage::RenderProcessTerminationStatus terminationStatus , int exitCode )

此信号被发射当渲染进程采用非零退出状态被终止时。 terminationStatus 是进程的终止状态,且 exitCode 是进程终止的状态码。

This function was introduced in Qt 5.6.

void QWebEnginePage:: replaceMisspelledWord (const QString & replacement )

Replace the current misspelled word with replacement .

The current misspelled word can be found in QWebEngineContextMenuData::misspelledWord (), and suggested replacements in QWebEngineContextMenuData::spellCheckerSuggestions ().

This function was introduced in Qt 5.8.

另请参阅 contextMenuData ().

void QWebEnginePage:: save (const QString & filePath , QWebEngineDownloadItem::SavePageFormat format = QWebEngineDownloadItem::MimeHtmlSaveFormat) const

把当前加载网页保存到磁盘。

网页被保存到 filePath 以指定 format .

这是以下动作的捷径:

  • 触发保存 Web 动作。
  • 接受下一下载项,并设置指定文件路径和保存格式。

此函数为网页发出异步下载请求,并立即返回。

This function was introduced in Qt 5.8.

另请参阅 QWebEngineDownloadItem::SavePageFormat .

QWebEngineScriptCollection &QWebEnginePage:: scripts ()

返回被注入到页面中的脚本集合。

此外,页面还可能执行添加脚本,透过 QWebEngineProfile::scripts ().

另请参阅 QWebEngineScriptCollection , QWebEngineScript ,和 脚本注入 .

[signal] void QWebEnginePage:: selectClientCertificate ( QWebEngineClientCertificateSelection clientCertificateSelection )

此信号被发射当网站请求 SSL 客户端证书,且在系统客户端证书存储中发现一个或多个。

处理信号是异步的,且加载会等待直到证书被选中,或上一拷贝 clientCertificateSelection 被销毁。

若信号未被处理, clientCertificateSelection 被自动销毁,且将在没有客户端证书的情况下继续加载。

This function was introduced in Qt 5.12.

另请参阅 QWebEngineClientCertificateSelection .

[signal] void QWebEnginePage:: selectionChanged ()

此信号被发射每当以交互或编程方式改变选定时。例如,通过调用 triggerAction () 采用选定动作。

注意: 当使用鼠标通过左键点击并拖曳以选择文本时,会为每个新选中字符发射信号,而不是在释放鼠标左键时。

另请参阅 selectedText ().

void QWebEnginePage:: setContent (const QByteArray & data , const QString & mimeType = QString(), const QUrl & baseUrl = QUrl())

Sets the content of the web page to data 。若 mimeType argument is empty, it is assumed that the content is text/plain,charset=US-ASCII .

External objects referenced in the content are located relative to baseUrl .

data is loaded immediately; external objects are loaded asynchronously.

注意: This method will not affect session or global history for the page.

警告: The content will be percent encoded before being sent to the renderer via IPC. This may increase its size. The maximum size of the percent encoded content is 2 megabytes minus 6 bytes plus the length of the mime type string.

另请参阅 toHtml () 和 setHtml ().

void QWebEnginePage:: setDevToolsPage ( QWebEnginePage * devToolsPage )

绑定 devToolsPage 成此页面的开发者工具。触发 devToolsPage 以采用开发者工具导航到内部 URL。

这如同调用 setInspectedPage () on devToolsPage with this 作为自变量。

This function was introduced in Qt 5.11.

另请参阅 devToolsPage () 和 setInspectedPage ().

void QWebEnginePage:: setFeaturePermission (const QUrl & securityOrigin , QWebEnginePage::Feature feature , QWebEnginePage::PermissionPolicy policy )

Sets the permission for the web site identified by securityOrigin to use feature to policy .

注意: Call this method on the featurePermissionRequested () signal, as it is meant to serve pending feature requests only. Setting feature permissions ahead of a request has no effect.

另请参阅 featurePermissionRequested () 和 featurePermissionRequestCanceled ().

void QWebEnginePage:: setHtml (const QString & html , const QUrl & baseUrl = QUrl())

Sets the content of this page to html . baseUrl is optional and used to resolve relative URLs in the document, such as referenced images or stylesheets.

html is loaded immediately; external objects are loaded asynchronously.

If a script in the html runs longer than the default script timeout (currently 10 seconds), for example due to being blocked by a modal JavaScript alert dialog, this method will return as soon as possible after the timeout and any subsequent html will be loaded asynchronously.

When using this method, the web engine assumes that external resources, such as JavaScript programs or style sheets, are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external script can be specified through the charset attribute of the HTML script tag. It is also possible for the encoding to be specified by the web server.

This is a convenience function equivalent to setContent (html, "text/html", baseUrl).

注意: This method will not affect session or global history for the page.

警告: This function works only for HTML, for other mime types (such as XHTML and SVG) setContent () should be used instead.

警告: The content will be percent encoded before being sent to the renderer via IPC. This may increase its size. The maximum size of the percent encoded content is 2 megabytes minus 30 bytes.

另请参阅 toHtml (), setContent (),和 load ().

void QWebEnginePage:: setInspectedPage ( QWebEnginePage * page )

Navigates this page to an internal URL that is the developer tools of page .

这如同调用 setDevToolsPage () on page with this 作为自变量。

This function was introduced in Qt 5.11.

另请参阅 inspectedPage () 和 setDevToolsPage ().

void QWebEnginePage:: setView ( QWidget * view )

设置 view 关联网页。

另请参阅 view ().

void QWebEnginePage:: setWebChannel ( QWebChannel * channel , uint worldId )

Sets the web channel instance to be used by this page to channel and connects it to web engine's transport using Chromium IPC messages. The transport is exposed in the JavaScript world worldId as qt.webChannelTransport , which should be used when using the Qt WebChannel JavaScript API .

注意: The page does not take ownership of the channel object.

注意: Only one web channel can be installed per page, setting one even in another JavaScript world uninstalls any already installed web channel.

This function was introduced in Qt 5.7.

另请参阅 webChannel () 和 QWebEngineScript::ScriptWorldId .

void QWebEnginePage:: setWebChannel ( QWebChannel * channel )

这是重载函数。

Sets the web channel instance to be used by this page to channel and installs it in the main JavaScript world.

With this method the web channel can be accessed by web page content. If the content is not under your control and might be hostile, this could be a security issue and you should consider installing it in a private JavaScript world.

This function was introduced in Qt 5.5.

另请参阅 QWebEngineScript::MainWorld .

QWebEngineSettings *QWebEnginePage:: settings () const

返回指向页面设置对象的指针。

另请参阅 QWebEngineSettings::globalSettings ().

[signal] void QWebEnginePage:: titleChanged (const QString & title )

此信号被发射每当页面标题改变时。 title 字符串指定新标题。

另请参阅 title ().

void QWebEnginePage:: toHtml (const QWebEngineCallback <const QString &> & resultCallback ) const

以 HTML 形式检索页面内容 (封闭于 HTML 和 BODY 标签) 的异步方法。成功完成后, resultCallback 被调用采用页面的内容。

注意: resultCallback 可以是函数指针、函子或 Lambda,且期望接受 QString 参数。

警告: 我们保证回调 ( resultCallback ) 总是被调用,但它可能在页面销毁期间完成。当 QWebEnginePage 被删除,会采用无效值触发回调,因此它是不安全的,去使用相应 QWebEnginePage or QWebEngineView 实例在其中。

另请参阅 setHtml () 和 toPlainText ().

void QWebEnginePage:: toPlainText (const QWebEngineCallback <const QString &> & resultCallback ) const

把检索页面内容 (完全剥离所有 HTML 格式) 转换为纯文本的异步方法。成功完成后, resultCallback 被调用采用页面的内容。

注意: resultCallback 可以是函数指针、函子或 Lambda,且期望接受 QString 参数。

警告: 我们保证回调 ( resultCallback ) 总是被调用,但它可能在页面销毁期间完成。当 QWebEnginePage 被删除,会采用无效值触发回调,因此它是不安全的,去使用相应 QWebEnginePage or QWebEngineView 实例在其中。

另请参阅 toHtml ().

[virtual] void QWebEnginePage:: triggerAction ( QWebEnginePage::WebAction action , bool checked = ...)

This function can be called to trigger the specified action . It is also called by Qt WebEngine if the user triggers the action, for example through a context menu item.

action is a checkable action, then checked specifies whether the action is toggled or not.

另请参阅 action ().

[signal] void QWebEnginePage:: urlChanged (const QUrl & url )

此信号被发射带页面 URL,当接收到页面标题时。新 URL 被指定由 url .

另请参阅 url ().

QWidget *QWebEnginePage:: view () const

返回与网页关联的视图 Widget。

另请参阅 setView ().

QWebChannel *QWebEnginePage:: webChannel () const

Returns a pointer to the web channel instance used by this page or a null pointer if none was set. This channel automatically uses the internal web engine transport mechanism over Chromium IPC that is exposed in the JavaScript context of this page as qt.webChannelTransport .

This function was introduced in Qt 5.5.

另请参阅 setWebChannel ().

[signal] void QWebEnginePage:: windowCloseRequested ()

此信号被发射每当页面请求关闭 Web 浏览器窗口时,例如透过 JavaScript window.close() 调用。

另请参阅 RequestClose .