From bf8862a3bfa3010986ed638e90d870fbd2a61435 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 6 Jun 2019 09:55:20 +0200 Subject: add std::function overload to qmlRegisterSingletonType This changes enables passing stateful lambdas to qmlRegisterSingletonType, which helps when porting away from setContextProperty. Unfortunately, we cannot directly add an overload for std::function, as this causes ambiguity in the overload set when a lambda of the form auto f = [](QQmlEngine*, QJSEngine*) -> QObject* is passed to the function (which is what the examples do) We therefore use a template to support abribtrary callables f, then SFINAE them out if f is not convertible to the desired std::function, or when f is convertible to a plain C function pointer, thus removing the ambiguity Change-Id: I6ca95ad692d8bb785e420b85bf3d8c1d0007ce17 Reviewed-by: Simon Hausmann --- src/qml/doc/src/qmlfunctions.qdoc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/qml/doc/src/qmlfunctions.qdoc') diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc index 3c80f16c8f..ab54b5fd1d 100644 --- a/src/qml/doc/src/qmlfunctions.qdoc +++ b/src/qml/doc/src/qmlfunctions.qdoc @@ -564,6 +564,14 @@ \sa {Choosing the Correct Integration Method Between C++ and QML} */ + +/*! + \fn int qmlRegisterSingletonType(const char *uri, int versionMajor, int versionMinor, const char *typeName, std::function callback) + \relates QQmlEngine + + \overload qmlRegisterSingletonType +*/ + /*! \fn int qmlRegisterSingletonType(const QUrl &url, const char *uri, int versionMajor, int versionMinor, const char *qmlName) \relates QQmlEngine -- cgit v1.2.3