Results 1 to 6 of 6

Thread: class MyReadOnlyTreeModel : public QAbstractItemModel

  1. #1
    Join Date
    Feb 2008
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Post class MyReadOnlyTreeModel : public QAbstractItemModel

    I need a fully working sample of
    class MyReadOnlyTreeModel : public QAbstractItemModel

    where the content is changed at run time by a worker thread.

    thanks.

  2. #2
    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: class MyReadOnlyTreeModel : public QAbstractItemModel

    Hmm... "ReadOnlyModel" that is changed? How about a small green sphere that looks like a big red cube?

    If you provide more details of what you want and tell us what you have already tried, then maybe we'll be able to help.

  3. #3
    Join Date
    Feb 2008
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: class MyReadOnlyTreeModel : public QAbstractItemModel

    Quote Originally Posted by wysota View Post
    Hmm... "ReadOnlyModel" that is changed? How about a small green sphere that looks like a big red cube?

    If you provide more details of what you want and tell us what you have already tried, then maybe we'll be able to help.

    Readonly meaning it does not implement setData() to allow the views to change data.
    But some threads can change the internal strucutre that is represented by the model, and
    this will lead the view to update correspondingly.

    Internal structure is something like:

    struct TheType
    {
    ...
    TheType* parent;
    List<TheType*> _chidren;
    };

    Does this sound reasonable or I'm missing something ?
    Or there is another approach for this ?

  4. #4
    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: class MyReadOnlyTreeModel : public QAbstractItemModel

    You'll need some synchronization mechanism if you want to use multiple threads when working on the model like that. But I'd suggest using signals and slots for updating the model.

    Take a look here: http://blog.wysota.eu.org/index.php/...remote-models/

    It deals with a similar problem (updating the model on the fly).

  5. #5
    Join Date
    Feb 2008
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: class MyReadOnlyTreeModel : public QAbstractItemModel

    Sorry, I think I have described the problem wrongly again. The problem is not in thread
    synchronization. Let's assume there is one thread only.

    You can take a look at the code attached, and here is what I would like to understand:

    1) After add-new-tree-item or update-an-existing-item in the internal tree, what to emit for
    the corresponding item to let the views know that info about that item has changed.

    2) I have tried many implementations for the model, and hardly can get it right.
    I suspect something is wrong there.

    3) The initial idea was to have a read-only model so that view can't modify it.
    but samples I found on read-only are populating data in the beginning only, not run time.

    4) any blaming to what I have posted, are welcome

    thanks
    Attached Files Attached Files

  6. #6
    Join Date
    Feb 2008
    Posts
    6
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: class MyReadOnlyTreeModel : public QAbstractItemModel

    oh, just saw the examples link there. my bad.

Similar Threads

  1. Coin3d + Qt: SIGLNALs and SLOTs
    By vonCZ in forum Newbie
    Replies: 26
    Last Post: 15th May 2009, 07:34
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. Delayed Rendering of QTabWidget Tabs
    By mclark in forum Qt Tools
    Replies: 13
    Last Post: 14th May 2007, 22:53
  4. link error for visual studio.net 2003
    By berlin in forum Newbie
    Replies: 9
    Last Post: 29th September 2006, 16:06
  5. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

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.