aboutsummaryrefslogtreecommitdiffstats
path: root/src
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 17:59:28 +0200
commitc551d02cb0fec2f3d753beb4ec38c14843518c33 (patch)
treeb034030f9802db8de16dff9b83e647c678207431 /src
parentfdbe0f21744a1cc1785cd10346437b03029fe65d (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). Change-Id: I07589974207bd5448d22a6086a52b9230d23e298 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 31c892118ce822ca2e7ded99ff261187ce4cf597)
Diffstat (limited to 'src')
-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));