summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativeloader/data/CreationContextLoader.qml15
-rw-r--r--tests/auto/declarative/qdeclarativeloader/data/creationContext.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp14
4 files changed, 40 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 1066c2b..5647b14 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -337,7 +337,9 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
return;
}
- QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(q));
+ QDeclarativeContext *creationContext = component->creationContext();
+ if (!creationContext) creationContext = qmlContext(q);
+ QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
ctxt->setContextObject(q);
QDeclarativeComponent *c = component;
diff --git a/tests/auto/declarative/qdeclarativeloader/data/CreationContextLoader.qml b/tests/auto/declarative/qdeclarativeloader/data/CreationContextLoader.qml
new file mode 100644
index 0000000..bfc9a8d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeloader/data/CreationContextLoader.qml
@@ -0,0 +1,15 @@
+import QtQuick 1.0
+
+Loader {
+ id: myLoader
+ property int testProperty: 1912
+ sourceComponent: loaderComponent
+ Component {
+ id: loaderComponent
+ Item {
+ Component.onCompleted: {
+ test = (myLoader.testProperty == 1912);
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeloader/data/creationContext.qml b/tests/auto/declarative/qdeclarativeloader/data/creationContext.qml
new file mode 100644
index 0000000..5297978
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeloader/data/creationContext.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.0
+
+Item {
+ property bool test: false
+
+ CreationContextLoader {
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
index 8d04616..1bde55b 100644
--- a/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
+++ b/tests/auto/declarative/qdeclarativeloader/tst_qdeclarativeloader.cpp
@@ -89,6 +89,7 @@ private slots:
void deleteComponentCrash();
void nonItem();
void vmeErrors();
+ void creationContext();
private:
QDeclarativeEngine engine;
@@ -562,6 +563,19 @@ void tst_QDeclarativeLoader::vmeErrors()
delete loader;
}
+// QTBUG-13481
+void tst_QDeclarativeLoader::creationContext()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("creationContext.qml"));
+
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+
+ QCOMPARE(o->property("test").toBool(), true);
+
+ delete o;
+}
+
QTEST_MAIN(tst_QDeclarativeLoader)
#include "tst_qdeclarativeloader.moc"