The QWebEngineFrame class gives information about and control over a page frame. 更多...
| 头: |
#include <QWebEngineFrame>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
|
| qmake: |
QT += webenginecore
|
| Since: | Qt 6.8 |
| 在 QML: | webEngineFrame |
| QList<QWebEngineFrame> | children () const |
| QString | htmlName () const |
| bool | isMainFrame () const |
| bool | isValid () const |
| QString | name () const |
| void | printToPdf (const QString & filePath ) |
| void | printToPdf (const std::function<void (const QByteArray &)> & callback ) |
| void | runJavaScript (const QString & script , const std::function<void (const QVariant &)> & callback ) |
| void | runJavaScript (const QString & script , quint32 worldId = 0) |
| void | runJavaScript (const QString & script , quint32 worldId , const std::function<void (const QVariant &)> & callback ) |
| QSizeF | size () const |
| QUrl | url () const |
| bool | operator!= (const QWebEngineFrame & left , const QWebEngineFrame & right ) |
| bool | operator== (const QWebEngineFrame & left , const QWebEngineFrame & right ) |
A web engine frame represents a single frame within a web page, such as those created by
<frame>
or
<iframe>
HTML elements. An active
QWebEnginePage
has one or more frames arranged in a tree structure. The top-level frame, the root of this tree, can be accessed through the mainFrame() method, and
children
() provides a frame's direct descendants.
A frame's lifetime is, at most, as long as the
QWebEnginePage
object that produced it. However, frames may be created and deleted spontaneously and dynamically, for example through navigation and script execution. Because of this, many QWebEngineFrame methods return optional values, which will be
std::nullopt
if the frame no longer exists.
[invokable]
void
QWebEngineFrame::
runJavaScript
(const
QString
&
script
,
quint32
worldId
= 0)
运行包含的 JavaScript 代码在
script
on this frame, without checking whether the DOM of the page has been constructed. To avoid conflicts with other scripts executed on the page, the world in which the script is run is specified by
worldId
。世界 ID 值是相同的提供通过
QWebEngineScript::ScriptWorldId
,和介于
0
and
256
。若忽略
world
ID,脚本运行在
MainWorld
. When the script has been executed,
callback
被调用带最后执行语句的结果。
callback
可以是函数指针、函子或 Lambda,且期望接受
QVariant
参数。例如:
page.runJavaScript("document.title", [](const QVariant &v) { qDebug() << v.toString(); });
仅纯数据可以被返回从 JavaScript 作为结果值。支持的数据类型包括所有 JSON 数据类型,例如,
Date
and
ArrayBuffer
。不支持的数据类型包括,例如,
Function
and
Promise
.
警告: 不要在回调函数中执行长例程,因为可能阻塞 Web 引擎页面的渲染。
警告: We guarantee that the callback is always called, but it might be done during page destruction. When QWebEnginePage 被删除,将采用无效值触发回调,因此是不安全的使用相应 QWebEnginePage or QWebEngineView 实例在其中。
另请参阅 QWebEngineScript::ScriptWorldId , QWebEnginePage::runJavaScript ,和 脚本注入 .
Returns a list of the frame's children in an arbitrary order.
If the frame could not be found, returns an empty list.
Returns the value of the frame's
name
HTML attribute, or an empty string if it has none.
If the frame could not be found, returns a null QString .
注意: Getter function for property htmlName.
另请参阅 name .
返回
true
if this object represents the page's main frame;
false
否则。
注意: Getter function for property isMainFrame.
返回
true
if this object represents an existing frame;
false
否则。
Once a frame is invalid, it never becomes valid again.
注意: Getter function for property isValid.
Returns the frame name; that is, what would be returned by
window.name
in JavaScript.
If the frame could not be found, returns a null QString .
注意: Getter function for property name.
另请参阅 htmlName .
[invokable]
void
QWebEngineFrame::
printToPdf
(const
QString
&
filePath
)
Renders the current content of the frame into a PDF document and saves it in the location specified in filePath . Printing uses a page size of A4, portrait layout, and includes the full range of pages.
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 QWebEnginePage::pdfPrintingFinished () 信号。
注意: The QWebEnginePage::Stop web action can be used to interrupt this asynchronous operation.
If a file already exists at the provided file path, it will be overwritten.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
另请参阅 QWebEnginePage::pdfPrintingFinished ().
Renders the current content of the frame into a PDF document and returns a byte array containing the PDF data as parameter to callback . Printing uses a page size of A4, portrait layout, and includes the full range of pages.
The callback 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.
注意: The QWebEnginePage::Stop web action can be used to interrupt this operation.
Returns the size of the frame within the viewport.
If the frame could not be found, returns QSizeF().
注意: Getter function for property size.
Returns the URL of the content currently loaded in this frame.
If the frame could not be found, returns an empty QUrl .
注意: Getter function for property url.
[noexcept]
bool
operator!=
(const
QWebEngineFrame
&
left
, const
QWebEngineFrame
&
right
)
返回
true
if
left
and
right
represent different frames in the same web page, otherwise
false
.
[noexcept]
bool
operator==
(const
QWebEngineFrame
&
left
, const
QWebEngineFrame
&
right
)
返回
true
if
left
and
right
represent the same frame in the same web page, otherwise
false
.