diff options
3 files changed, 54 insertions, 9 deletions
diff --git a/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp b/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp index 12f06e6b76..d338508d09 100644 --- a/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp +++ b/src/declarative/qml/v8/qdeclarativebuiltinfunctions.cpp @@ -1096,8 +1096,17 @@ v8::Handle<v8::Value> createQmlObject(const v8::Arguments &args) V8THROW_ERROR("Qt.createQmlObject(): Component is not ready"); QObject *obj = component.beginCreate(effectiveContext); - if (obj) + if (obj) { QDeclarativeData::get(obj, true)->setImplicitDestructible(); + + obj->setParent(parentArg); + + QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions(); + for (int ii = 0; ii < functions.count(); ++ii) { + if (QDeclarativePrivate::Parented == functions.at(ii)(obj, parentArg)) + break; + } + } component.completeCreate(); if (component.isError()) { @@ -1107,14 +1116,6 @@ v8::Handle<v8::Value> createQmlObject(const v8::Arguments &args) Q_ASSERT(obj); - obj->setParent(parentArg); - - QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions(); - for (int ii = 0; ii < functions.count(); ++ii) { - if (QDeclarativePrivate::Parented == functions.at(ii)(obj, parentArg)) - break; - } - return v8engine->newQObject(obj); } diff --git a/tests/auto/declarative/qdeclarativecomponent/data/createParentReference.qml b/tests/auto/declarative/qdeclarativecomponent/data/createParentReference.qml new file mode 100644 index 0000000000..daa5d3c167 --- /dev/null +++ b/tests/auto/declarative/qdeclarativecomponent/data/createParentReference.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Item { + id: root + width: 100 + height: 100 + + function createChild() { + Qt.createQmlObject("import QtQuick 2.0;" + + "Item { width: parent.width; }", root); + } +} diff --git a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp index c529649fc0..993c706092 100644 --- a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp +++ b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp @@ -71,6 +71,7 @@ private slots: void qmlCreateObject(); void qmlCreateObjectWithProperties(); void qmlIncubateObject(); + void qmlCreateParentReference(); private: QDeclarativeEngine engine; @@ -181,6 +182,37 @@ void tst_qdeclarativecomponent::qmlCreateObjectWithProperties() delete testBindingThisObj; } +static QStringList warnings; +static void msgHandler(QtMsgType, const char *warning) +{ + warnings << QString::fromUtf8(warning); +} + +void tst_qdeclarativecomponent::qmlCreateParentReference() +{ + QDeclarativeEngine engine; + + QCOMPARE(engine.outputWarningsToStandardError(), true); + + warnings.clear(); + QtMsgHandler old = qInstallMsgHandler(msgHandler); + + QDeclarativeComponent component(&engine, testFileUrl("createParentReference.qml")); + QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8()); + QObject *object = component.create(); + QVERIFY(object != 0); + + QVERIFY(QMetaObject::invokeMethod(object, "createChild")); + delete object; + + qInstallMsgHandler(old); + + engine.setOutputWarningsToStandardError(false); + QCOMPARE(engine.outputWarningsToStandardError(), false); + + QCOMPARE(warnings.count(), 0); +} + QTEST_MAIN(tst_qdeclarativecomponent) #include "tst_qdeclarativecomponent.moc" |