diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2019-05-02 14:45:35 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2019-06-07 10:43:16 +0200 |
commit | d73497cf770c92e38903850267fd8737df3578ca (patch) | |
tree | bd8523d20d750bd3461e959df0e4865137ac914a /src/corelib/kernel/qobject.h | |
parent | 9dec965248503836ad478b1c1ffdd7f34aed048b (diff) |
QObject/QWidget::setParent: add assertions to prevent loops
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 <liang.qi@qt.io>
Reviewed-by: Sérgio Martins <sergio.martins@kdab.com>
Diffstat (limited to 'src/corelib/kernel/qobject.h')
-rw-r--r-- | src/corelib/kernel/qobject.h | 4 |
1 files changed, 4 insertions, 0 deletions
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 }; |