Results 1 to 9 of 9

Thread: how to update a tree view model

  1. #1
    Join Date
    Dec 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default how to update a tree view model

    I have a question about how to update a tree view model when data changes. I will try to explain my problem by looking at the simpletreemodel example shipped with qt4.Lets assume I extend the example with a button, which will add some tree item (TreeItem instance) to the tree. Now, how can I update the visable QAbstractItemModel (TreeModel class) with these new changes.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to update a tree view model

    a model and a view will be updated automatically. when data in model have been changed, model notify a view that the data have been changed and then view updates itself.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to update a tree view model


  4. #4
    Join Date
    Dec 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to update a tree view model

    Quote Originally Posted by spirit View Post
    a model and a view will be updated automatically. when data in model have been changed, model notify a view that the data have been changed and then view updates itself.
    Thanks,

    But the treeModel is my own model which refer to the simpletreemodel example
    shipped with qt4. It can't be updated automatically, when data in model have been changed.

    Regards.

  5. #5
    Join Date
    Dec 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to update a tree view model

    Quote Originally Posted by talk2amulya View Post
    Thanks, but it can't help.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to update a tree view model

    so, you use own model, right? so, when you change data you need to emit signal QAbstractItemModel::dataChanged.

    you have to listen talk2amulya and read last link.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. The following user says thank you to spirit for this useful post:

    chow (26th March 2009)

  8. #7
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to update a tree view model

    if you read those links, your problem would be solved undoubtedly..also, u say

    It can't be updated automatically, when data in model have been changed.
    u say data in model is changed then what is not updated automatically? its simple:
    1. make your item editable
    2. use setData(..)
    3. change ur model/source of model
    4. emit dataChanged()

  9. #8
    Join Date
    Dec 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to update a tree view model

    Quote Originally Posted by talk2amulya View Post
    if you read those links, your problem would be solved undoubtedly..also, u say



    u say data in model is changed then what is not updated automatically? its simple:
    1. make your item editable
    2. use setData(..)
    3. change ur model/source of model
    4. emit dataChanged()

    But the problem is ..

    Lets assume I extend the example with a button, which will add some tree
    item (TreeItem instance) to the tree. Now, how can I update the
    visable QAbstractItemModel (TreeModel class) with these new changes.
    One way I found, I think, is to call the reset() member function of
    QAbstractItemModel, but this is a bit drastic, because it will parse the
    whole tree again.

    An other solution, I assume, is to emit a dataChanged() signal or a
    layoutChaged() signal. The problem I have with these signals is that
    a have no clue on how to create the arguments (QModelIndex) in case
    of a tree view.

    An other problem is that the layoutChanged() signal does not seems to be
    documented in Qt assistant.

  10. #9
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to update a tree view model

    Lets assume I extend the example with a button, which will add some tree
    item (TreeItem instance) to the tree
    Dont assume... get started and try an example... I guess the Qt Demos will be sufficient for the problems u face.. see how they add data in the model...
    still if you cant make it work, then post the prob u get,,, but get started first

  11. The following user says thank you to aamer4yu for this useful post:

    chow (26th March 2009)

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 21:17
  2. How use Model view with a tree wich have Cycle ?
    By weepdoo in forum Qt Programming
    Replies: 2
    Last Post: 9th December 2008, 18:05
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 09:50
  4. Replies: 9
    Last Post: 7th November 2006, 16:10
  5. Replies: 6
    Last Post: 20th April 2006, 11:23

Tags for this Thread

Bookmarks

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.