diff options
author | Kimmo Ollila <kimmo.ollila@theqtcompany.com> | 2016-03-10 09:46:40 +0200 |
---|---|---|
committer | Kimmo Ollila <kimmo.ollila@theqtcompany.com> | 2016-03-16 13:43:57 +0000 |
commit | 7c9fe368de133a6b4e256392e0db0d6c3dc1cf9a (patch) | |
tree | e2462fe843cb8ed41c1261fed07cb8713a5d48e1 /src/imports/bluetoothsettings | |
parent | c6b5855b446c73f8a60cc3d4427fc445e0ba400d (diff) |
Use qmlRegisterSingletonType instead of setContextProperty in plugins
Change-Id: Ib6c6c7bc5e5e1db005dd43222163fceb50c8894a
Reviewed-by: Teemu Holappa <teemu.holappa@theqtcompany.com>
Diffstat (limited to 'src/imports/bluetoothsettings')
-rw-r--r-- | src/imports/bluetoothsettings/plugin.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
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 <typename T> +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<BtDeviceItem>(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<BluetoothDevice>(uri, 1, 0, "BtDevice", &instance<BluetoothDevice>); } }; |