From d73497cf770c92e38903850267fd8737df3578ca Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 2 May 2019 14:45:35 +0200 Subject: QObject/QWidget::setParent: add assertions to prevent loops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is perfectly possible to accidentally create a parent/child loop. This can happens by direct means (a->setParent(b); b->setParent(a);), or some more subtle means, e.g. class MyClass : public QObject { MyClass() : QObject(this) {} }; Since this is UB, add a few robustness checks to make sure the code above crashes right away (at least in debug builds). Change-Id: I6583c8514b4c1f8a90677b04c77b8e8f0c15dba3 Reviewed-by: Liang Qi Reviewed-by: Sérgio Martins --- src/corelib/kernel/qobject.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/corelib/kernel/qobject.h') diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index ad5e1163bf..7f72b69c1a 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -113,6 +113,10 @@ public: int postedEvents; QDynamicMetaObjectData *metaObject; QMetaObject *dynamicMetaObject() const; + +#ifdef QT_DEBUG + enum { CheckForParentChildLoopsWarnDepth = 4096 }; +#endif }; -- cgit v1.2.3