Results 1 to 4 of 4

Thread: Populate a custom model

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Populate a custom model

    Hi everyone !

    I have navigated through the Internet all day to find an answer to my question, but it seems that the answer is too obvious to be posted on the web. So here it is :

    How do I set custom items to my custom models ?

    I have been on the Qt Doc page related to the QAbstracItemModel, and have no clue on which methods to call to let the model know I created new rows (tried beginInsertRows() / insertRow () / endInsertRows() but it did not seem to have any effect) and even if I would have succeeded, how will the model know that he has to check on my QList<MyCustomItem *> to populate himself (and create the QModelIndexes that I'll need to use afterwards).

    I hope I have been clear enough on my questions (I could have linked my code, but it is quite long).

    I thank you for any answer, and am sorry for my poor english.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Populate a custom model

    Yes, beginInsertRows() and endInsertRows() make sure that any view using the model will know to update itself.

    So you
    1) call beginInsertRows()
    2) modify your list
    3) call endInsertRows()

    Assuming of course you have implemented rowCount() to check the size of the list and data() to access the list.
    And columnCount() in case this is a table model.

    Which of the three base classes did you derive from?

    Cheers,
    _

Similar Threads

  1. Replies: 4
    Last Post: 20th October 2014, 11:12
  2. Replies: 9
    Last Post: 14th February 2013, 20:39
  3. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 21:23
  4. How to populate delegate with model data.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2008, 10:31
  5. Replies: 1
    Last Post: 10th October 2007, 11:11

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
  •  
Qt is a trademark of The Qt Company.