-
This commit is contained in:
@@ -2,6 +2,32 @@
|
||||
|
||||
#include "webviewqt.h"
|
||||
#include "rktwebview_qt.h"
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
#include <QJsonObject>
|
||||
|
||||
void WebviewWindow::processJsEvents()
|
||||
{
|
||||
QWebEnginePage *p = _view->page();
|
||||
p->runJavaScript("window.getPendingEvents();",
|
||||
[this](const QVariant &v) {
|
||||
QString s = v.toString();
|
||||
QJsonParseError err;
|
||||
QJsonDocument doc(QJsonDocument::fromJson(s.toUtf8(), &err));
|
||||
if (err.error == QJsonParseError::NoError) {
|
||||
QJsonArray a = doc.array();
|
||||
int i, N;
|
||||
for(i = 0, N = a.size(); i < N; i++) {
|
||||
QJsonObject evt = a[i].toObject();
|
||||
QJsonDocument doc_out(evt);
|
||||
QString msg = doc_out.toJson(QJsonDocument::JsonFormat::Compact);
|
||||
this->_container->triggerJsEvent(_view->id(), msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void WebviewWindow::closeEvent(QCloseEvent *evt)
|
||||
{
|
||||
@@ -13,6 +39,11 @@ void WebviewWindow::addView(WebViewQt *v, Rktwebview_qt *c)
|
||||
_container = c;
|
||||
_view = v;
|
||||
this->setCentralWidget(v);
|
||||
|
||||
QWebEnginePage *page = _view->page();
|
||||
connect(page, &QWebEnginePage::loadFinished, this, [this](bool ok) {
|
||||
_container->pageLoaded(_view->id(), ok);
|
||||
});
|
||||
}
|
||||
|
||||
WebViewQt *WebviewWindow::view()
|
||||
@@ -24,4 +55,5 @@ WebviewWindow::WebviewWindow(QWidget *parent)
|
||||
: QMainWindow{parent}
|
||||
{
|
||||
_view = nullptr;
|
||||
connect(&_process_js_events, &QTimer::timeout, this, &WebviewWindow::processJsEvents);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user