diff options
author | Antti Piira <apiira@blackberry.com> | 2013-10-28 16:17:36 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-09 22:46:47 +0100 |
commit | 7b75c3e63e7842c2667f58d43d44e21ff57ac0c8 (patch) | |
tree | 2aa1ade5d31c099170b65b8b618257bf330321dd /src/qml/qml/qqml.h | |
parent | bed4d0de7e4bf57dd70e44be28eb361b4f4fe9e2 (diff) |
Add a new variant of qmlRegisterSingletonType for QML singletons.
Adds a new public API to register a QML based singleton type from
C++. This is the equivalent of the the qmlRegisterType, but for
singletons. qmldir file is not needed for types registered through
this function, but the type still needs to include the following
pragma statement among the import statements:
pragma Singleton
Change-Id: Icb35b665fe2a8605667fe8ac575347be2a60490c
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqml.h')
-rw-r--r-- | src/qml/qml/qqml.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h index 6082fcda08..b6c6fe840d 100644 --- a/src/qml/qml/qqml.h +++ b/src/qml/qml/qqml.h @@ -485,6 +485,24 @@ inline int qmlRegisterSingletonType(const char *uri, int versionMajor, int versi return QQmlPrivate::qmlregister(QQmlPrivate::SingletonRegistration, &api); } +inline int qmlRegisterSingletonType(const QUrl &url, const char *uri, int versionMajor, int versionMinor, const char *qmlName) +{ + if (url.isRelative()) { + // User input check must go here, because QQmlPrivate::qmlregister is also used internally for composite types + qWarning("qmlRegisterSingletonType requires absolute URLs."); + return 0; + } + + QQmlPrivate::RegisterCompositeSingletonType type = { + url, + uri, + versionMajor, + versionMinor, + qmlName + }; + + return QQmlPrivate::qmlregister(QQmlPrivate::CompositeSingletonRegistration, &type); +} inline int qmlRegisterType(const QUrl &url, const char *uri, int versionMajor, int versionMinor, const char *qmlName) { |