diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2020-07-23 17:29:11 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2020-07-27 17:59:28 +0200 |
commit | c551d02cb0fec2f3d753beb4ec38c14843518c33 (patch) | |
tree | b034030f9802db8de16dff9b83e647c678207431 /tests/auto/qml/qqmlinfo/attached.cpp | |
parent | fdbe0f21744a1cc1785cd10346437b03029fe65d (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 'tests/auto/qml/qqmlinfo/attached.cpp')
-rw-r--r-- | tests/auto/qml/qqmlinfo/attached.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlinfo/attached.cpp b/tests/auto/qml/qqmlinfo/attached.cpp new file mode 100644 index 0000000000..f4b866a547 --- /dev/null +++ b/tests/auto/qml/qqmlinfo/attached.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "attached.h" + +Attached::Attached(QObject *parent) : + QObject(parent) +{ +} + +int Attached::a() const +{ + return mA; +} + +void Attached::setA(int a) +{ + // Intentionally omit the early return in order to force a binding loop. + + mA = a; + emit aChanged(); +} + +Attached *Attached::qmlAttachedProperties(QObject *object) +{ + return new Attached(object); +} |