[PyQt] Maintaining index after sort

Andreas Pakulat apaku at gmx.de
Sun May 29 10:03:58 BST 2011


On 28.05.11 21:58:36, Marc Rossi wrote:
> Hi all.  Hopefully this is the correct place.  Google searches etc, came up
> empty although I have to think this is a common question.
> 
> I have a Model-View app using the QAbstractTableModel as the base class for
> my model.  As I receive data across the tcp pipe (using PyZMQ) I check if
> this is a new item or an update by looking to see if I already have an index
> for the data received.

Model indexes are not meant to be stored over time, they're short-lived
objects. You could try Persistent Model Indexes, which are meant to be
stored. 

But you don't need the index at all, your model just needs a function
that takes the sinfo and updates its internal structure by using
sinfo.symbol to identify which entry to update. In fact I think the
if/else you've showed should be part of the model, so that the outside
can simply do something like: model.addData(sinfo).

Andreas



More information about the PyQt mailing list