aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2020-07-23 17:29:11 +0200
committerMitch Curtis <mitch.curtis@qt.io>2020-07-27 14:43:48 +0200
commit31c892118ce822ca2e7ded99ff261187ce4cf597 (patch)
tree00cf756baee3542a263cec906056d7770f89117a /tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp
parent9a204084fd4d68650dad7e0a018429cf0486c3a1 (diff)
QQmlInfo: print ancestor of object if it has no QML engine
This results in the following message for objects without a QML engine: QML AttachedObject (parent or ancestor of Attached): Binding loop detected for property "a" for this QML file, named AttachedObject.qml: import QtQuick 2.0 import org.qtproject.Test 1.0 Item { Attached.a: Attached.a } This, in turn, allows the warning to be emitted via the QQmlEngine::warnings signal, since QQmlEnginePrivate::warning() is now passed a valid engine. This solves the awkward situation where a binding loop warning can not be detected at all by auto tests involving attached C++ objects (as message handlers do not receive these messages either). Pick-to: 5.15 Change-Id: I07589974207bd5448d22a6086a52b9230d23e298 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp')
-rw-r--r--tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp
index 706102e6fe..bb96ba319c 100644
--- a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp
+++ b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
#include <qtest.h>
+#include <QtTest/qsignalspy.h>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QTimer>
@@ -34,6 +35,8 @@
#include <qqmlinfo.h>
#include "../../shared/util.h"
+#include "attached.h"
+
class tst_qqmlinfo : public QQmlDataTest
{
Q_OBJECT
@@ -51,6 +54,7 @@ private slots:
void chaining();
void messageTypes();
void component();
+ void attachedObject();
private:
QQmlEngine engine;
@@ -230,6 +234,34 @@ void tst_qqmlinfo::component()
qmlInfo(delegate) << "Delegate error";
}
+void tst_qqmlinfo::attachedObject()
+{
+ QQmlComponent component(&engine, testFileUrl("AttachedObject.qml"));
+
+ QSignalSpy warningSpy(&engine, SIGNAL(warnings(const QList<QQmlError> &)));
+ QVERIFY(warningSpy.isValid());
+
+ const QString qmlBindingLoopMessage = "QML Rectangle: Binding loop detected for property \"width\"";
+ const QString qmlBindingLoopMessageFull = component.url().toString() + ":7:5: " + qmlBindingLoopMessage;
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(qmlBindingLoopMessageFull));
+
+ const QString cppBindingLoopMessage = "QML AttachedObject (parent or ancestor of Attached): Binding loop detected for property \"a\"";
+ const QString cppBindingLoopMessageFull = component.url().toString() + ":4:1: " + cppBindingLoopMessage;
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(cppBindingLoopMessageFull));
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(object != nullptr, qPrintable(component.errorString()));
+ QCOMPARE(warningSpy.count(), 2);
+
+ // The Attached C++ type has no QML engine since it was created in C++, so we should see its parent instead.
+ const auto cppWarnings = warningSpy.at(0).first().value<QList<QQmlError>>();
+ QCOMPARE(cppWarnings.first().description(), cppBindingLoopMessage);
+
+ // The QML type has a QML engine, so we should see the normal message.
+ const auto qmlWarnings = warningSpy.at(1).first().value<QList<QQmlError>>();
+ QCOMPARE(qmlWarnings.first().description(), qmlBindingLoopMessage);
+}
+
QTEST_MAIN(tst_qqmlinfo)
#include "tst_qqmlinfo.moc"