QWebEngineFrame Class

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.

成員函數文檔編製

void QWebEngineFrame:: runJavaScript (const QString & script , const std::function < void (const QVariant &)> & callback )

[invokable] void QWebEngineFrame:: runJavaScript (const QString & script , quint32 worldId = 0)

void QWebEngineFrame:: runJavaScript (const QString & script , quint32 worldId , const std::function < void (const QVariant &)> & callback )

運行包含的 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 ,和 腳本注入 .

QList < QWebEngineFrame > QWebEngineFrame:: children () const

Returns a list of the frame's children in an arbitrary order.

If the frame could not be found, returns an empty list.

注意: Getter function for property children.

QString QWebEngineFrame:: htmlName () const

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 .

bool QWebEngineFrame:: isMainFrame () const

返迴 true if this object represents the page's main frame; false 否則。

注意: Getter function for property isMainFrame.

bool QWebEngineFrame:: isValid () const

返迴 true if this object represents an existing frame; false 否則。

Once a frame is invalid, it never becomes valid again.

注意: Getter function for property isValid.

QString QWebEngineFrame:: 名稱 () const

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.

若提供的文件路徑已存在,將覆寫它。

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

另請參閱 QWebEnginePage::pdfPrintingFinished ().

void QWebEngineFrame:: printToPdf (const std::function < void (const QByteArray &)> & callback )

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 必須接受 const 引用對 QByteArray 作為參數。若打印成功,此字節數組將包含 PDF 數據,否則,字節數組將為空。

注意: The QWebEnginePage::Stop web action can be used to interrupt this operation.

QSizeF QWebEngineFrame:: size () const

Returns the size of the frame within the viewport, measured in logical pixels. On devices with a scale factor other than 100%, this will not correspond to the on-screen size; instead, it will be the size before scaling is applied. In such cases, the size may contain fractional values.

If the frame could not be found, returns QSizeF().

注意: Getter function for property size.

QUrl QWebEngineFrame:: url () const

Returns the URL of the content currently loaded in this frame.

If the frame could not be found, returns an empty QUrl .

注意: getter 函數對於特性 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 .