aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/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 /src/qml/qml/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 'src/qml/qml/qqmlinfo.cpp')
-rw-r--r--src/qml/qml/qqmlinfo.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlinfo.cpp b/src/qml/qml/qqmlinfo.cpp
index 7204d5ccd2..8852f609e9 100644
--- a/src/qml/qml/qqmlinfo.cpp
+++ b/src/qml/qml/qqmlinfo.cpp
@@ -212,11 +212,24 @@ QQmlInfo::~QQmlInfo()
QObject *object = const_cast<QObject *>(d->object);
if (object) {
- engine = qmlEngine(d->object);
+ // Some objects (e.g. like attached objects created in C++) won't have an associated engine,
+ // but we can still try to look for a parent object that does.
+ QObject *objectWithEngine = object;
+ while (objectWithEngine) {
+ engine = qmlEngine(objectWithEngine);
+ if (engine)
+ break;
+ objectWithEngine = objectWithEngine->parent();
+ }
- d->buffer.prepend(QLatin1String("QML ") + QQmlMetaType::prettyTypeName(object) + QLatin1String(": "));
+ if (!objectWithEngine || objectWithEngine == object) {
+ d->buffer.prepend(QLatin1String("QML ") + QQmlMetaType::prettyTypeName(object) + QLatin1String(": "));
+ } else {
+ d->buffer.prepend(QLatin1String("QML ") + QQmlMetaType::prettyTypeName(objectWithEngine)
+ + QLatin1String(" (parent or ancestor of ") + QQmlMetaType::prettyTypeName(object) + QLatin1String("): "));
+ }
- QQmlData *ddata = QQmlData::get(object, false);
+ QQmlData *ddata = QQmlData::get(objectWithEngine ? objectWithEngine : object, false);
if (ddata && ddata->outerContext) {
error.setUrl(ddata->outerContext->url());
error.setLine(qmlConvertSourceCoordinate<quint16, int>(ddata->lineNumber));