Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/qmlplugin.cpp
Show All 17 Lines | |||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | 19 | * | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "qmlplugin.h" | 22 | #include "qmlplugin.h" | ||
23 | 23 | | |||
24 | #include "quickengine.h" | 24 | #include "quickengine.h" | ||
25 | #include "quickitemsmodel.h" | 25 | #include "quickitemsmodel.h" | ||
26 | #include "quickquestionlistener.h" | ||||
27 | #include "author.h" | ||||
28 | #include "categoriesmodel.h" | ||||
29 | #include "commentsmodel.h" | ||||
26 | #include "downloadlinkinfo.h" | 30 | #include "downloadlinkinfo.h" | ||
27 | 31 | | |||
32 | #include "provider.h" | ||||
33 | #include "question.h" | ||||
34 | | ||||
28 | #include <QQmlEngine> | 35 | #include <QQmlEngine> | ||
29 | #include <qqml.h> | 36 | #include <qqml.h> | ||
30 | 37 | | |||
31 | void QmlPlugins::initializeEngine(QQmlEngine *engine, const char *) | 38 | void QmlPlugins::initializeEngine(QQmlEngine *engine, const char *) | ||
32 | { | 39 | { | ||
33 | Q_UNUSED(engine); | 40 | Q_UNUSED(engine); | ||
34 | } | 41 | } | ||
35 | 42 | | |||
36 | void QmlPlugins::registerTypes(const char *uri) | 43 | void QmlPlugins::registerTypes(const char *uri) | ||
37 | { | 44 | { | ||
38 | qmlRegisterType<Engine>(uri, 1, 0, "Engine"); | 45 | qmlRegisterType<Engine>(uri, 1, 0, "Engine"); | ||
39 | qmlRegisterType<ItemsModel>(uri, 1, 0, "ItemsModel"); | 46 | qmlRegisterType<ItemsModel>(uri, 1, 0, "ItemsModel"); | ||
47 | qmlRegisterType<KNewStuffQuick::Author>(uri, 1, 62, "Author"); | ||||
48 | qmlRegisterType<KNewStuffQuick::CommentsModel>(uri, 1, 62, "CommentsModel"); | ||||
40 | qmlRegisterUncreatableType<DownloadLinkInfo>(uri, 1, 0, "DownloadLinkInfo", QStringLiteral("This should only be created by the ItemsModel, and is associated with one entry in that model")); | 49 | qmlRegisterUncreatableType<DownloadLinkInfo>(uri, 1, 0, "DownloadLinkInfo", QStringLiteral("This should only be created by the ItemsModel, and is associated with one entry in that model")); | ||
50 | qmlRegisterUncreatableType<CategoriesModel>(uri, 1, 0, "CategoriesModel", QStringLiteral("This should only be created by the Engine, and provides the categories available in that engine")); | ||||
51 | qmlRegisterUncreatableMetaObject(KNSCore::Provider::staticMetaObject, "org.kde.newstuff.core", 1, 62, "Provider", QLatin1String("Error: this only exists to forward enums")); | ||||
52 | qmlRegisterUncreatableMetaObject(KNSCore::Question::staticMetaObject, "org.kde.newstuff.core", 1, 62, "Question", QLatin1String("Error: this only exists to forward enums")); | ||||
53 | qmlRegisterSingletonType<KNewStuffQuick::QuickQuestionListener>(uri, 1, 62, "QuickQuestionListener", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { | ||||
54 | Q_UNUSED(scriptEngine) | ||||
55 | engine->setObjectOwnership(KNewStuffQuick::QuickQuestionListener::instance(), QQmlEngine::CppOwnership); | ||||
56 | return KNewStuffQuick::QuickQuestionListener::instance(); | ||||
ahiemstra: Note that this makes the qml engine take ownvership of your singleton instance and it will try… | |||||
Hmm... Quite. It doesn't really matter functionally, but the code in the QuickQuestionListener suggests that it's cpp owned, so yeah, let's just do that :) leinir: Hmm... Quite. It doesn't really matter functionally, but the code in the QuickQuestionListener… | |||||
57 | }); | ||||
41 | } | 58 | } |
Note that this makes the qml engine take ownvership of your singleton instance and it will try to delete it when the engine gets deleted. You probably want to do engine->setOwnership(instance, QQmlEngine::CppOwnership) before returning the instance.