summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
authorEirik Aavitsland <[email protected]>2024-12-10 15:40:12 +0100
committerEirik Aavitsland <[email protected]>2024-12-12 15:27:14 +0100
commit73221d263823d50e525858d613ce93769698454a (patch)
tree4bcc88c8f0f5b026677485b4d51a7847ecc99a17 /src/widgets/kernel
parentb7419557b1b0cc1a87aa91131329b65aee44ec34 (diff)
QWidget::mapTo()/mapFrom(): Do not crash if parent argument is invalid
These functions iterate through the parent hierarchy until the widget given as argument is found. If never found, the code would assert (in debug mode) or just silently crash (in release mode). No need to bring down the entire application just because some widget coordinate calculation is off. Instead, just emit a qWarning and return cleanly. Task-number: QTBUG-132072 Pick-to: 6.9 6.8 Change-Id: I4d13f46037cdcf855f76e040f941a8a7050ab12b Reviewed-by: Richard Moe Gustavsen <[email protected]>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/qwidget.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index dc1abe70cc4..683285011f5 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -4219,10 +4219,12 @@ QPointF QWidget::mapTo(const QWidget *parent, const QPointF &pos) const
if (parent) {
const QWidget * w = this;
while (w != parent) {
- Q_ASSERT_X(w, "QWidget::mapTo(const QWidget *parent, const QPointF &pos)",
- "parent must be in parent hierarchy");
p = w->mapToParent(p);
w = w->parentWidget();
+ if (!w) {
+ qWarning("QWidget::mapTo(): parent must be in parent hierarchy");
+ break;
+ }
}
}
return p;
@@ -4251,11 +4253,12 @@ QPointF QWidget::mapFrom(const QWidget *parent, const QPointF &pos) const
if (parent) {
const QWidget * w = this;
while (w != parent) {
- Q_ASSERT_X(w, "QWidget::mapFrom(const QWidget *parent, const QPoint &pos)",
- "parent must be in parent hierarchy");
-
p = w->mapFromParent(p);
w = w->parentWidget();
+ if (!w) {
+ qWarning("QWidget::mapFrom(): parent must be in parent hierarchy");
+ break;
+ }
}
}
return p;