把 QObject 暴露給遠程 HTML 客戶端。 更多...
| 頭: | #include <QWebChannel> |
| qmake: | QT += webchannel |
| 繼承: | QObject |
| QWebChannel (QObject * parent = nullptr) | |
| virtual | ~QWebChannel () |
| QBindable<bool> | bindableBlockUpdates () |
| QBindable<int> | bindablePropertyUpdateInterval () |
| bool | blockUpdates () const |
| void | deregisterObject (QObject * object ) |
| int | propertyUpdateInterval () const |
| void | registerObject (const QString & id , QObject * object ) |
| void | registerObjects (const QHash<QString, QObject *> & 對象 ) |
| QHash<QString, QObject *> | registeredObjects () const |
| void | setBlockUpdates (bool block ) |
| void | setPropertyUpdateInterval (int ms ) |
| void | connectTo (QWebChannelAbstractTransport * transport ) |
| void | disconnectFrom (QWebChannelAbstractTransport * transport ) |
| void | blockUpdatesChanged (bool block ) |
QWebChannel 填充 C++ 應用程序和 HTML/JavaScript 應用程序之間的間隙。通過發布 QObject 派生對象給 QWebChannel 並使用 qwebchannel.js on the HTML side, one can transparently access properties and public slots and methods of the QObject 。不需要手動傳遞消息和序列化數據,在 C++ 側的特性更新和信號發齣,會被自動傳輸到潛在的遠程運行 HTML 客戶端。在客戶端側,JavaScript 對象將被創建,為任何已發布 C++ QObject 。它鏡像 C++ 對象的 API,因此,是直觀可用的。
QWebChannel transparently supports QFuture . When a client calls a method that returns a QFuture , QWebChannel will send a response with the QFuture result only after the QFuture has finished.
C++ QWebChannel API 使與任何 HTML 客戶端對話成為可能,這些客戶端可以運行在本地 (甚至遠程機器上)。唯一的限製是 HTML 客戶端要支持 JavaScript 特徵,要求使用
qwebchannel.js
。因此,基本上可以與任何現代 HTML 瀏覽器或獨立 JavaScript 運行時 (如 node.js) 交互。
還存在聲明式 WebChannel API .
另請參閱 Qt WebChannel 獨立範例 and JavaScript API .
[bindable]
blockUpdates
:
bool
注意: This property supports QProperty 綁定。
當設為 true 時,更新被阻塞,且不會通知遠程客戶端有關特性的更改。
改變被記錄並被發送給客戶端,一旦更新再次變為不阻塞,通過把此特性設為 false。默認情況下,更新不被阻塞。
[bindable]
propertyUpdateInterval
:
int
注意: This property supports QProperty 綁定。
This property holds the property update interval.
This interval can be changed to a different interval in milliseconds by setting it to a positive value. Property updates are batched and sent out after the interval expires. If set to zero, the updates occurring within a single event loop run are batched and sent out on the next run. If negative, updates will be sent immediately. Default value is 50 milliseconds.
[explicit]
QWebChannel::
QWebChannel
(
QObject
*
parent
= nullptr)
構造 QWebChannel 對象采用給定 parent .
注意:QWebChannel 纔完整可操作,一旦把它連接到
QWebChannelAbstractTransport
。HTML 客戶端還需進行適當設置使用
qwebchannel.js
.
[虛擬]
QWebChannel::
~QWebChannel
()
銷毀 QWebChannel .
[slot]
void
QWebChannel::
connectTo
(
QWebChannelAbstractTransport
*
transport
)
連接 QWebChannel 到給定 transport 對象。
然後,傳輸對象處理 C++ 應用程序和遠程 HTML 客戶端之間的通信。
另請參閱 QWebChannelAbstractTransport and QWebChannel::disconnectFrom ().
[invokable]
void
QWebChannel::
deregisterObject
(
QObject
*
object
)
撤銷注冊給定 object 從 QWebChannel .
遠程客戶端會接收
destroyed
信號對於給定對象。
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
另請參閱 QWebChannel::registerObjects (), QWebChannel::registerObject (),和 QWebChannel::registeredObjects ().
[slot]
void
QWebChannel::
disconnectFrom
(
QWebChannelAbstractTransport
*
transport
)
斷開連接 QWebChannel 從 transport 對象。
另請參閱 QWebChannel::connectTo ().
[invokable]
void
QWebChannel::
registerObject
(const
QString
&
id
,
QObject
*
object
)
把單個對象注冊到 QWebChannel .
The properties, signals and public methods of the object are published to the remote clients. There, an object with the identifier id 然後被構造。
注意:
A property that is
BINDABLE
but does not have a
NOTIFY
signal will have working property updates on the client side, but no mechanism to register a callback for the change notifications.
注意: 當前的限製是對象被注冊,在任何客戶端被初始化之前。
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
另請參閱 QWebChannel::registerObjects (), QWebChannel::deregisterObject (),和 QWebChannel::registeredObjects ().
把對象組注冊到 QWebChannel .
對象的特性、信號及公共可援引方法被發布到遠程客戶端。在那裏,對象采用標識符用作為鍵在 objects 映射然後被構造。
注意: 當前的限製是對象被注冊,在任何客戶端被初始化之前。
另請參閱 QWebChannel::registerObject (), QWebChannel::deregisterObject (),和 QWebChannel::registeredObjects ().
返迴被發布到遠程客戶端的注冊對象的映射。
另請參閱 QWebChannel::registerObjects (), QWebChannel::registerObject (),和 QWebChannel::deregisterObject ().