summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/widgets/browser/browsermainwindow.cpp26
-rw-r--r--examples/widgets/fancybrowser/mainwindow.cpp26
-rw-r--r--tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp4
-rw-r--r--tests/auto/widgets/util.h30
4 files changed, 51 insertions, 35 deletions
diff --git a/examples/widgets/browser/browsermainwindow.cpp b/examples/widgets/browser/browsermainwindow.cpp
index ac8426d9a..26b38c921 100644
--- a/examples/widgets/browser/browsermainwindow.cpp
+++ b/examples/widgets/browser/browsermainwindow.cpp
@@ -71,15 +71,21 @@
#include <QtCore/QDebug>
-#if __cplusplus >= 201103L
-#include <functional>
-using std::bind;
-namespace placeholders = std::placeholders;
-#else
-#include <tr1/functional>
-using std::tr1::bind;
-namespace placeholders = std::tr1::placeholders;
-#endif
+template<typename Arg, typename R, typename C>
+struct InvokeWrapper {
+ R *receiver;
+ void (C::*memberFun)(const Arg&);
+ void operator()(const Arg &result) {
+ (receiver->*memberFun)(result);
+ }
+};
+
+template<typename Arg, typename R, typename C>
+InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(const Arg&))
+{
+ InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun};
+ return wrapper;
+}
BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags)
@@ -827,7 +833,7 @@ void BrowserMainWindow::slotViewPageSource()
view->setAttribute(Qt::WA_DeleteOnClose);
view->show();
- currentTab()->page()->toHtml(bind(&QPlainTextEdit::setPlainText, view, placeholders::_1));
+ currentTab()->page()->toHtml(invoke(view, &QPlainTextEdit::setPlainText));
}
void BrowserMainWindow::slotHome()
diff --git a/examples/widgets/fancybrowser/mainwindow.cpp b/examples/widgets/fancybrowser/mainwindow.cpp
index b9d5a8364..9462539e5 100644
--- a/examples/widgets/fancybrowser/mainwindow.cpp
+++ b/examples/widgets/fancybrowser/mainwindow.cpp
@@ -42,15 +42,21 @@
#include <QtWebEngineWidgets>
#include "mainwindow.h"
-#if __cplusplus >= 201103L
-#include <functional>
-using std::bind;
-namespace placeholders = std::placeholders;
-#else
-#include <tr1/functional>
-using std::tr1::bind;
-namespace placeholders = std::tr1::placeholders;
-#endif
+template<typename Arg, typename R, typename C>
+struct InvokeWrapper {
+ R *receiver;
+ void (C::*memberFun)(const Arg&);
+ void operator()(const Arg &result) {
+ (receiver->*memberFun)(result);
+ }
+};
+
+template<typename Arg, typename R, typename C>
+InvokeWrapper<Arg, R, C> invoke(R *receiver, void (C::*memberFun)(const Arg&))
+{
+ InvokeWrapper<Arg, R, C> wrapper = {receiver, memberFun};
+ return wrapper;
+}
//! [1]
@@ -120,7 +126,7 @@ void MainWindow::viewSource()
textEdit->move(this->geometry().center() - textEdit->rect().center());
textEdit->show();
- view->page()->toHtml(bind(&QTextEdit::setPlainText, textEdit, placeholders::_1));
+ view->page()->toHtml(invoke(textEdit, &QTextEdit::setPlainText));
}
//! [4]
diff --git a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp
index 99ad21152..b38a7fdfe 100644
--- a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp
+++ b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp
@@ -406,8 +406,8 @@ void tst_QWebEngineFrame::asyncAndDelete()
QWebEnginePage *page = new QWebEnginePage;
CallbackSpy<QString> plainTextSpy;
CallbackSpy<QString> htmlSpy;
- page->toPlainText(ref(plainTextSpy));
- page->toHtml(ref(htmlSpy));
+ page->toPlainText(plainTextSpy.ref());
+ page->toHtml(htmlSpy.ref());
delete page;
// Pending callbacks should be called with an empty value in the page's destructor.
diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h
index a9a3d487c..5adc7e1b7 100644
--- a/tests/auto/widgets/util.h
+++ b/tests/auto/widgets/util.h
@@ -27,14 +27,6 @@
#include <QTimer>
#include <qwebenginepage.h>
-#if __cplusplus >= 201103L
-#include <functional>
-using std::ref;
-#else
-#include <tr1/functional>
-using std::tr1::ref;
-#endif
-
#if !defined(TESTS_SOURCE_DIR)
#define TESTS_SOURCE_DIR ""
#endif
@@ -87,12 +79,17 @@ public:
}
};
+template<typename T, typename R>
+struct RefWrapper {
+ R &ref;
+ void operator()(const T& result) {
+ ref(result);
+ }
+};
+
template<typename T>
class CallbackSpy {
public:
- // Tells tr1::ref the result of void operator()(const T &result) when decltype isn't available.
- typedef void result_type;
-
CallbackSpy() : called(false) {
timeoutTimer.setSingleShot(true);
QObject::connect(&timeoutTimer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
@@ -116,6 +113,13 @@ public:
eventLoop.quit();
}
+ // Cheap rip-off of boost/std::ref
+ RefWrapper<T, CallbackSpy<T> > ref()
+ {
+ RefWrapper<T, CallbackSpy<T> > wrapper = {*this};
+ return wrapper;
+ }
+
private:
Q_DISABLE_COPY(CallbackSpy)
bool called;
@@ -127,14 +131,14 @@ private:
static inline QString toPlainText(QWebEnginePage *page)
{
CallbackSpy<QString> spy;
- page->toPlainText(ref(spy));
+ page->toPlainText(spy.ref());
return spy.waitForResult();
}
static inline QString toHtml(QWebEnginePage *page)
{
CallbackSpy<QString> spy;
- page->toHtml(ref(spy));
+ page->toHtml(spy.ref());
return spy.waitForResult();
}