From 00afb51baaf0b0398ba7780dec491cf144dad0d9 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 12 Sep 2018 09:33:47 +0200 Subject: QQuickTableView: sync model and delegate when ready to do so Doing (silly) things in the delegate, like: Component.onCompleted: TableView.view.delegate = null will lead to a crash. The same if you change the model. The reason is that you end up changing the model while e.g a row is half-way loaded. Information needed for building the row, like model size, will then be invalid. To protect against this, we insert a "sync" phase to the code that takes any such changes into effect at a time when we know it's safe to do so. Change-Id: I85a992dfc0e04ec6635b10c9768a8ddc140e09da Reviewed-by: Mitch Curtis --- src/quick/items/qquicktableview_p_p.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/quick/items/qquicktableview_p_p.h') diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h index 9ff2b2e10b..6bf3de76df 100644 --- a/src/quick/items/qquicktableview_p_p.h +++ b/src/quick/items/qquicktableview_p_p.h @@ -206,6 +206,11 @@ public: QPointer tableModel = nullptr; QVariant modelVariant; + // When the applications assignes a new model or delegate to the view, we keep them + // around until we're ready to take them into use (syncWithPendingChanges). + QVariant assignedModel = QVariant(int(0)); + QQmlComponent *assignedDelegate = nullptr; + // loadedTable describes the table cells that are currently loaded (from top left // row/column to bottom right row/column). loadedTableOuterRect describes the actual // pixels that those cells cover, and is matched agains the viewport to determine when @@ -332,6 +337,11 @@ public: void itemReusedCallback(int modelIndex, QObject *object); void modelUpdated(const QQmlChangeSet &changeSet, bool reset); + inline void syncWithPendingChanges(); + inline void syncDelegate(); + inline void syncModel(); + inline void syncRebuildOptions(); + void connectToModel(); void disconnectFromModel(); -- cgit v1.2.3