aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktableview.cpp
diff options
context:
space:
mode:
authorSanthosh Kumar <santhosh.kumar.selvaraj@qt.io>2023-06-27 14:26:06 +0200
committerSanthosh Kumar <santhosh.kumar.selvaraj@qt.io>2023-06-28 21:29:19 +0200
commit4bd3738a4ee0b2124793ddb45367ff6e459f4b55 (patch)
treecef07bbed56b74a8e73f71e7097b9354de72e3a8 /src/quick/items/qquicktableview.cpp
parent7407b4db29c2b04a78885f8444b3d118fdd1cb27 (diff)
Fix crash while positioning zero sized table view
TableView expects view size to be specified for loading model items within it. If not specified, it doesn't load any items (change made after patch set ebefb583c886dba86aa51012fb377762235f2379). If user positions the view through positionViewAtCell or positionViewAtColumn or positionViewAtRow without specifying view size, then the TableView crashes and its an unexpected behavior. This patch set adds validation in the TableView to check for loaded columns or rows during positioning. The document also been updated to show the expected behavior of TableView when size not specified. Fixes: QTBUG-113738 Pick-to: 6.5 6.6 Change-Id: Ibd72caada5bfeb290ab5eff3b9ead1e07b3a7176 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r--src/quick/items/qquicktableview.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 49ba247372..2f161cb4bb 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -44,6 +44,12 @@
using the \l HorizontalHeaderView and \l VerticalHeaderView from
Qt Quick Controls.
+ \note TableView will only \l {isRowLoaded()}{load} as many delegate items as
+ needed to fill up the view. There is no guarantee that items outside the view
+ will be loaded, although TableView will sometimes pre-load items for
+ optimization reasons. Hence, a TableView with zero width or height might not
+ load any delegate items at all.
+
\section1 Example Usage
\section2 C++ Models
@@ -5682,7 +5688,7 @@ int QQuickTableView::currentColumn() const
void QQuickTableView::positionViewAtRow(int row, PositionMode mode, qreal offset, const QRectF &subRect)
{
Q_D(QQuickTableView);
- if (row < 0 || row >= rows())
+ if (row < 0 || row >= rows() || d->loadedRows.isEmpty())
return;
// Note: PositionMode::Contain is from here on translated to (Qt::AlignTop | Qt::AlignBottom).
@@ -5748,7 +5754,7 @@ void QQuickTableView::positionViewAtRow(int row, PositionMode mode, qreal offset
void QQuickTableView::positionViewAtColumn(int column, PositionMode mode, qreal offset, const QRectF &subRect)
{
Q_D(QQuickTableView);
- if (column < 0 || column >= columns())
+ if (column < 0 || column >= columns() || d->loadedColumns.isEmpty())
return;
// Note: PositionMode::Contain is from here on translated to (Qt::AlignLeft | Qt::AlignRight).