Correct Use of QAbstractTableModel::beginInsertRows() for non-consecutive rows



  • What should I do if I need to insert data rows into the model but the data goes into different, non-consecutive rows?

    In my case, the data has a QDateTime timestamp and the model might need to add data from previous or future timestamps.

    Docs say "Specify the first and last row numbers for the span of rows you want to insert into an item in a model.".

    So let's say I have 10 rows in my model. Now I got 4 new items that need to be inserted. But there's a chance that some would need to be prepended, some would go in the middle and some would be appended.

    Am I supposed to calculate the destinated ranges beforehand, and then call beginInsertRows() for each consecutive range?


  • Lifetime Qt Champion

    Hi,

    That's what I would do, it will also allow views to react properly


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.