[Interest] What is beginInsertRows() purpose?

Paul Miller stelefx at gmail.com
Fri Aug 23 16:16:17 CEST 2013


On 8/23/2013 9:08 AM, Etienne Sandré-Chardonnal wrote:
> But... I always wondered why it is necessary to have both signals (one
> before and one after) in the underlying mechanism, and what could be
> wrong in doing:
>
> -modify the model underlying data structure by inserting rows-
> beginInsertRows()
> endInsertRows()
>
> Instead of the regular:
> beginInsertRows()
> -modify the model underlying data structure by inserting rows-
> endInsertRows()
>
> It's always better to understand why are things done how they are...

begin/endInsertRows/Columns tells the view that you are about to change 
the model. Views can then "wait" to refresh or build their internal data 
structures until the rows/columns have been inserted in the model. Since 
view updates could be expensive, this is a useful optimization.

If you're doing a lot of complex model updates, such as 
inserting/deleting lots of rows you could always just call modelReset(), 
but depending on the view that may cause the view to scroll back to the top.




More information about the Interest mailing list