Results 1 to 9 of 9

Thread: [QT4]QTreeView, QAbstractItemModel and a MySQL database

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: [QT4]QTreeView, QAbstractItemModel and a MySQL database

    The view doesn't do any caching by itself. It is always the models responsibility. If you want a "retrieve on demand" approach, you have to code it yourself in the model. For example have a tree which has items and each item can be marked as "complete" or "unknown" and when data from a child of a "unknown" item is fetched, just query the database and attach new elements to the tree before returning the result. You'll have to watch for the "columnCount()" and "rowCount()" methods, because if you don't implement them right, you'll end up with filling the whole tree at the beginning.

  2. #2
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: [QT4]QTreeView, QAbstractItemModel and a MySQL database

    This is the response from the Trolltech QT support. The QAbstractProxyModel seems to be a good possibility to map between different model structures.




    > Is there a way to tell the QTreeView to cache the data and only to
    > requery it when the Model tells it to do so?

    Not out of the box.

    > If I need to create my own cache tree structure (wich I actually fear
    > I need to do), is there something within QT that lets me create such a
    > tree in a comfortable way? Something like the DOM tools but without
    > the XML.

    Not really, but using a combination of QMap<> and QVector<> might be
    what you want, i.e. something like this

    struct Node
    {
    QMap<QString, QVariant> values;
    Node* parent;
    QVector<Node*> children;
    };

    and then provide some accessor functions that add/remove children and
    values or something similar. You could then use the QAbstractProxyModel
    class to provide mapping from your real model (if you have an existing
    one or if you're currently using one of the SQL models).

    Hope this helps.

    --
    Jan Erik Hanssen
    Trolltech AS, Oslo - http://www.trolltech.com

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

    KShots (7th March 2006)

  4. #3
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: [QT4]QTreeView, QAbstractItemModel and a MySQL database

    Thanks. For my case, I'll likely do something different, but that would work for the general case.
    Life without passion is death in disguise

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.