summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-04 11:31:28 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-04 11:31:28 (GMT)
commit179f6e9ac1c9b4a7902e791ad1e8d105179fe4da (patch)
tree9c61fa78fd999cf0d51c44c51a2bf815b3ca27e6
parentffc3973cbdf1e7942037583bb89ba53722a6b862 (diff)
Improve test apps
-rw-r--r--webengineviewer/src/tests/testjquerysupportwebengine.cpp30
-rw-r--r--webengineviewer/src/tests/testjquerysupportwebengine.h1
2 files changed, 30 insertions, 1 deletions
diff --git a/webengineviewer/src/tests/testjquerysupportwebengine.cpp b/webengineviewer/src/tests/testjquerysupportwebengine.cpp
index ab5d425..d53d0b4 100644
--- a/webengineviewer/src/tests/testjquerysupportwebengine.cpp
+++ b/webengineviewer/src/tests/testjquerysupportwebengine.cpp
@@ -24,9 +24,31 @@
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
+#include <QPointer>
#include <WebEngineViewer/WebEngineManageScript>
#include <WebEngineViewer/WebEnginePage>
+
+template<typename Arg, typename R, typename C>
+struct InvokeWrapper {
+ QPointer<R> receiver;
+ void (C::*memberFunction)(Arg);
+ void operator()(Arg result)
+ {
+ if (receiver) {
+ (receiver->*memberFunction)(result);
+ }
+ }
+};
+
+template<typename Arg, typename R, typename C>
+
+InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFunction)(Arg))
+{
+ InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFunction};
+ return wrapper;
+}
+
TestJQuerySupportWebEngine::TestJQuerySupportWebEngine(QWidget *parent)
: QWidget(parent)
{
@@ -60,12 +82,18 @@ void TestJQuerySupportWebEngine::slotShowConsoleMessage(const QString &message)
qDebug() <<"TestJQuerySupportWebEngine::slotShowConsoleMessage :"<<message;
}
+void TestJQuerySupportWebEngine::handleResultScript(const QVariant &var)
+{
+ qDebug() << " void TestJQuerySupportWebEngine::handleResultScript(const QVariant &var)"<<var;
+}
+
void TestJQuerySupportWebEngine::slotExecuteQuery()
{
const QString code = mEditor->toPlainText();
if (!code.isEmpty()) {
#if QT_VERSION >= 0x050700
- pageView->page()->runJavaScript(code, WebEngineViewer::WebEngineManageScript::scriptWordId());
+ pageView->page()->runJavaScript(code, WebEngineViewer::WebEngineManageScript::scriptWordId(),
+ invoke(this, &TestJQuerySupportWebEngine::handleResultScript));
#else
pageView->page()->runJavaScript(code);
#endif
diff --git a/webengineviewer/src/tests/testjquerysupportwebengine.h b/webengineviewer/src/tests/testjquerysupportwebengine.h
index 8b62a14..a76f1d2 100644
--- a/webengineviewer/src/tests/testjquerysupportwebengine.h
+++ b/webengineviewer/src/tests/testjquerysupportwebengine.h
@@ -38,6 +38,7 @@ private Q_SLOTS:
void slotExecuteQuery();
private:
+ void handleResultScript(const QVariant &var);
void slotShowConsoleMessage(const QString &message);
WebEngineViewer::WebEngineView *pageView;
QTextEdit *mEditor;