summaryrefslogtreecommitdiffstats
path: root/examples/widgets/doc/src
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-03-22 10:11:11 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2023-03-28 08:59:53 +0000
commit585bfe600a158743d68e4c8c81fb1a7106566d6a (patch)
treef59818d7bfea578409195ef99534b788629dfe59 /examples/widgets/doc/src
parentdf0b661bfc015bfe3eaeed3e811d63c91929e61c (diff)
Fix pointer mismatch after QList::move() in tooltip example
The tooltip example moves shape items within a QWidget. Shape items are stored in a QList of objects. When an item is moved, its pointer is taken from the QList and stored in a member variable. To have the moved item on the bottom of the list, QList::move() is called. This operation re-arranges the list objects, and the member variable starts pointing at a wrong object. This patch changes the list from a list of objects, to a list of pointers. Shape items are therefore allocated on the heap. A destructor is added to free the heap with qDeleteAll. The example's documentation is adapted accordingly and a snippet for the destructor is added. As a drive-by, int is replaced by qsizetype where it was used as an index of a QList. Fixes: QTBUG-104781 Pick-to: 6.5 6.2 Change-Id: I9be26fa7954be5f85729d24f166d66980af71801 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'examples/widgets/doc/src')
-rw-r--r--examples/widgets/doc/src/tooltips.qdoc16
1 files changed, 10 insertions, 6 deletions
diff --git a/examples/widgets/doc/src/tooltips.qdoc b/examples/widgets/doc/src/tooltips.qdoc
index 4712c80851..3af3768f00 100644
--- a/examples/widgets/doc/src/tooltips.qdoc
+++ b/examples/widgets/doc/src/tooltips.qdoc
@@ -124,6 +124,10 @@
private \c createShapeItem(), \c initialItemPosition() and \c
initialItemColor() functions.
+ \snippet widgets/tooltips/sortingbox.cpp 27
+
+ In the destructor, we delete all shape items.
+
\snippet widgets/tooltips/sortingbox.cpp 5
QWidget::event() is the main event handler and receives all the
@@ -199,8 +203,9 @@
If an item covers the position, we store a pointer to that item
and the event's position. If several of the shape items cover the
position, we store the pointer to the uppermost item. Finally, we
- move the shape item to the end of the list, and make a call to the
- QWidget::update() function to make the item appear on top.
+ move the shape item's pointer to the end of the list, and make
+ a call to the QWidget::update() function to make the item appear
+ on top.
The QWidget::update() function does not cause an immediate
repaint; instead it schedules a paint event for processing when Qt
@@ -290,10 +295,9 @@
The \c createShapeItem() function creates a single shape item. It
sets the path, tooltip, position and color, using the item's own
- functions. In the end, the function appends the new item to the
- list of shape items, and calls the QWidget::update() function to
- make it appear with the other items within the \c SortingBox
- widget.
+ functions. In the end, the function appends the new item's pointer
+ to the list of shape items, and calls QWidget::update() to make
+ it appear with the other items within the \c SortingBox widget.
\snippet widgets/tooltips/sortingbox.cpp 22