From 5e0c3a798ab0d70be45a107661fc5f0a17322a2a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 2 Mar 2018 09:09:17 +0100 Subject: Fix calling Qt.createComponent() from QQmlEngine::evaluate() If we're run from a top-level evaluate() call from the JS engine, then let's assume that any created components are top-level components that belong to the root QML engine context. This is not quite a typical use-case, but our API allows for this and this seems like an easy and sensible solution. Task-number: QTBUG-66792 Change-Id: Ic1c9171c257e8e60c0b2c43f9194bd038744ed2d Reviewed-by: Oleg Yadrov Reviewed-by: Michael Brasser --- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/qml/qml') diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index c147feeb73..1371f1f041 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -1119,6 +1119,11 @@ ReturnedValue QtObject::method_createQmlObject(const FunctionObject *b, const Va QQmlEngine *engine = scope.engine->qmlEngine(); QQmlContextData *context = scope.engine->callingQmlContext(); + if (!context) { + QQmlEngine *qmlEngine = scope.engine->qmlEngine(); + if (qmlEngine) + context = QQmlContextData::get(QQmlEnginePrivate::get(qmlEngine)->rootContext); + } Q_ASSERT(context); QQmlContext *effectiveContext = nullptr; if (context->isPragmaLibraryContext) @@ -1246,6 +1251,11 @@ ReturnedValue QtObject::method_createComponent(const FunctionObject *b, const Va QQmlEngine *engine = scope.engine->qmlEngine(); QQmlContextData *context = scope.engine->callingQmlContext(); + if (!context) { + QQmlEngine *qmlEngine = scope.engine->qmlEngine(); + if (qmlEngine) + context = QQmlContextData::get(QQmlEnginePrivate::get(qmlEngine)->rootContext); + } Q_ASSERT(context); QQmlContextData *effectiveContext = context; if (context->isPragmaLibraryContext) -- cgit v1.2.3