summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject.cpp
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2025-08-21 11:45:41 +0200
committerAxel Spoerl <axel.spoerl@qt.io>2025-08-22 10:55:15 +0200
commitac47344ed735462b9aa562789f632ea474746d82 (patch)
treefb50f631fed2fdddf6d8eaefdb2851d52e95e156 /src/corelib/kernel/qobject.cpp
parent35dbd1c3f4beec55812c633c1c1ccedc4a71335a (diff)
Implement QObject::isQmlObjectType()
QObject::isQuickItemType() indicates whether a QObject inherits QQuickItem. However, QML code can add plain QObjects, which are not QQuickItems. It could not be established whether QObject was created by the QML engine without including private headers. Implement QObject::isQmlObjectType(), returning true a QObject was created by the QML engine, or ownership has been set via QJSEngine API. Add documentation. An autotest has to be added in qtdeclarative. Task-number: QTBUG-139351 Change-Id: I783ab3384118d02a0a7d4aaf6b375d3ec0a9969b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r--src/corelib/kernel/qobject.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 991d88c6ee0..7e5078bf58c 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -1416,6 +1416,18 @@ QBindable<QString> QObject::bindableObjectName()
*/
/*!
+ \fn bool QObject::isQmlObjectType() const
+ Returns whether the object has been created by the QML engine or
+ ownership has been explicitly set via QJSEngine::setObjectOwnership().
+ \since 6.11
+*/
+bool QObject::isQmlObjectType() const
+{
+ Q_D(const QObject);
+ return !d->isDeletingChildren && d->declarativeData;
+}
+
+/*!
This virtual function receives events to an object and should
return true if the event \a e was recognized and processed.