Results 1 to 4 of 4

Thread: QAbstractItemModel container members?

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

    Default QAbstractItemModel container members?

    Hello,

    I've just started using QAbstractItemModel and QModelIndex with the intent of storing data that I will subsquently display in a QTableWidget subclass and also manipulate in other ways etc. I sort of expected that QAbstractItemModel would contain its own (private) container members so that I could just enter in and retrieve cell data with accessor members like setData(...)/data(). (Like wxGrid and wxGridTableBase.) However, given how data(), rowCount(), and columnCount() are pure virtual, and SetData(...) "... must be reimplemented for editable models." (documentation), and finally that QModelIndex::data() just refers back to its QAbstractItemModel, it looks like this is not true. I.e., I have to create my own container member, such as a vector, to store data values, and implement the above-named functions to access/manipulate *that*.

    Is this right? If so then I kind of wonder what QAbstractItemModel is for--i.e., why not just create my own little TableDataStorage class with a vector, setData()/data() functions, and use that? Or to put it another way--do you guys in general find QAbstractItemModel to be useful? Thanks--

    Matt

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemModel container members?

    • the QAbstract*Model classes do not contain any internal data store. They are meant to be subclassed to offer a model abstraction over an existing data store and that's what make them so useful : you can use model view without altering or converting your existing data structures
    • these classes cannot be used in conjunction with Q(Table|List|Tree)Widget but only with Q(Table|List|Tree)View because the former use an internal subclass of QAbstract*Model classes with their own data store.
    • it would be just fine to create a model class using vectors as data storage. Just make sure you also offer an alternate way of accessing that data (i.e not through model/view API) for use in other parts of your program.

    hope this helps
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Jan 2006
    Location
    Shanghai, China
    Posts
    52
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemModel container members?

    The QAbstract*Model classes are just defining consistence interfaces for those View classes to use.
    Think of that. How can we write a general view class withou those abstract models? What model type should we put there for the setModel funtion?
    1. Users don't have the manual, and if they did, they wouldn't read it.
    2. In fact, users can't read anything, and if they could, they wouldn't want to.

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

    Default Re: QAbstractItemModel container members?

    Thanks guys--since my last post, after a tour through the Qt source, I have managed to figure out how these work, and I'm starting to appreciate their usefulness. Probably more so as I start to get into big datasets that I need to do math on.

    Matt

Similar Threads

  1. How to make QAbstractItemModel 's data checkable
    By nifei in forum Qt Programming
    Replies: 12
    Last Post: 1st April 2013, 20:52
  2. Replies: 3
    Last Post: 7th August 2009, 11:21
  3. Container Extensions
    By mariok in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 12:06
  4. container populated with custom widgets
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 16th April 2006, 22:02

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.