Results 1 to 5 of 5

Thread: Threaded refreshing of a TreeView with custom model

  1. #1
    Join Date
    Aug 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Threaded refreshing of a TreeView with custom model

    I work on a big project using QTreeView with a custom model. I did a longer break because of other interests but more importantly because of a big (design) problem which I couldn't solve.
    I often have to change the content of the tree view. I know layoutChanged has to be used there but it doesn't work in this case. I have to do a bigger process which uses a second thread and a progress window. While this will be done events of the model will be progressed on so many functions (index, parent...).
    So the question is how this can be prevented. Please help I absolutely have no idea.

    To explain it in more details. If through fetchMore happens a "special" case a longer progress starts in a second thread. In all other cases there is no problem. It took me some time to figure out that index and parent will be called from old or new events. I started with tries to ignore those calls but it could happen in too many functions and is a very bad method. All signals from Qt couldn't be used (modelReset) or used without effect.

    There is no use of the tree view in the progress it's only to see how long it takes and for canceling so it could be disabled or something similar.

  2. #2
    Join Date
    Aug 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Threaded refreshing of a TreeView with custom model

    I somehow clicked on the wrong section. Could someone please move this thread to qt Programming?

  3. #3
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Threaded refreshing of a TreeView with custom model

    I suggest you let your second thread aggregate the data in some struct and, once finished, update your model in one go using that struct. That way you avoid both the view accessing a partially updated model and have just one "update".

    Also note that the model must only be updated from the gui thread.

  4. #4
    Join Date
    Aug 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Threaded refreshing of a TreeView with custom model

    I suggest you let your second thread aggregate the data in some struct and, once finished, update your model in one go using that struct. That way you avoid both the view accessing a partially updated model and have just one "update".
    As you may think that's surely something I thought about earlier and it's a very complicated go. I will have a look again but I hoped for different solutions.

    Also note that the model must only be updated from the gui thread.
    I know the implementation works but most times it crashes because of the written reason.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Threaded refreshing of a TreeView with custom model

    You should use the concept of snapshots - snapshot (copy) the current data at the same time blocking user changes to the model (if applicable), rearrange the copied model data in the other thread and when you're done, attach the data back to the main root of the model.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 12
    Last Post: 5th July 2009, 17:03
  2. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 17:26
  3. Custom proxy model issue
    By Khal Drogo in forum Qt Programming
    Replies: 13
    Last Post: 30th November 2007, 13:41
  4. Treeview and custom model
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 15th May 2007, 14:54
  5. TreeView custom model
    By steg90 in forum Newbie
    Replies: 1
    Last Post: 9th May 2007, 11:06

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.