From 7c9fe368de133a6b4e256392e0db0d6c3dc1cf9a Mon Sep 17 00:00:00 2001 From: Kimmo Ollila Date: Thu, 10 Mar 2016 09:46:40 +0200 Subject: Use qmlRegisterSingletonType instead of setContextProperty in plugins Change-Id: Ib6c6c7bc5e5e1db005dd43222163fceb50c8894a Reviewed-by: Teemu Holappa --- src/imports/bluetoothsettings/plugin.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/imports/bluetoothsettings') diff --git a/src/imports/bluetoothsettings/plugin.cpp b/src/imports/bluetoothsettings/plugin.cpp index d0a25c3..20f5b28 100644 --- a/src/imports/bluetoothsettings/plugin.cpp +++ b/src/imports/bluetoothsettings/plugin.cpp @@ -43,6 +43,13 @@ #include "bluetoothdevice.h" #include "discoverymodel.h" +template +QObject *instance(QQmlEngine *engine, QJSEngine *) { + T *t = new T(engine); + t->setObjectName(T::staticMetaObject.className()); + return t; +} + class BluetoothSettingsQmlPlugin : public QQmlExtensionPlugin { Q_OBJECT @@ -53,14 +60,7 @@ public: { Q_ASSERT(QLatin1String(uri) == QLatin1String("com.theqtcompany.settings.bluetooth")); qmlRegisterUncreatableType(uri, 1, 0, "BtDeviceItem", "Cannot be instantiated directly."); - - } - - void initializeEngine(QQmlEngine * engine, const char * uri) - { - Q_ASSERT(QLatin1String(uri) == QLatin1String("com.theqtcompany.settings.bluetooth")); - BluetoothDevice *device = new BluetoothDevice(engine); - engine->rootContext()->setContextProperty("BtDevice", device); + qmlRegisterSingletonType(uri, 1, 0, "BtDevice", &instance); } }; -- cgit v1.2.3