aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-02-23 14:55:16 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-23 07:02:04 +0100
commitdc3165178851b9bda71dd238c8a5faca4dfa7a45 (patch)
tree40878590bc6c6299d454fec42a630d334461fd84 /tests
parentbbbc44c45d9a6b7381b775413fcfcc1a72c14317 (diff)
Remove warning produced by 'parent' reference.
When Qt.createQmlObject is invoked from QML, any contained references to parent produce a warning from V8. To prevent this, move the assignment of the parent object to before the initial execution of the bindings. Task-number: QTBUG-24464 Change-Id: Ib330822f1ca46ec5a6af648a56197da09669c3f2 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativecomponent/data/createParentReference.qml12
-rw-r--r--tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp32
2 files changed, 44 insertions, 0 deletions
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"