Results 1 to 2 of 2

Thread: Using internal data structure with model/view architecture

  1. #1
    Join Date
    Feb 2006
    Oslo, Norway
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Using internal data structure with model/view architecture

    Just to get the concept right and before starting to implement anything..
    I'm thinking of writing a model for a quite complex data object structure.

    The internal data structure would consist of several different types of
    objects laid in a hierachical tree.

    Now the question is, if I wanna connect signals to (and modify) the objects
    in the internal data structure, how is the model/view architecture supposed
    to detect the changes?

    Do I need to make a connection between the model and each object in
    the internal data structure to explicitly inform about changes?
    Or is there any more elegant way to achieve this kind of behaviour?

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: Using internal data structure with model/view architecture

    As long as you reimplement and use methods from QAbstractItemModel, all things related to the view will be updated correctly. Now, if you want to change objects of the model without using standard model calls (mainly setData(), beingInsert/RemoveRows(), etc.), you have to make sure the model is aware of those changes and signals that some things have changed (signals layoutChanged() and dataChanged() handle this). But in general you should incorporate methods changing those objects into the model, so that you can emit proper signals. If you feel like doing otherwise, you just need a way to emit those signals from the model, meaning that those objects have to call some method defined in the model, which knows how to distinguish between objects and knows how to check what exactly changed (the layout or the data) and emits proper signals in either case.

  3. The following user says thank you to wysota for this useful post:

    jpn (3rd April 2006)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.