Results 1 to 5 of 5

Thread: How to tell a QAbstractItemModel that data has been inserted or removed? (4.8)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to tell a QAbstractItemModel that data has been inserted or removed? (4.8)

    If something causes say, a row to be inserted in the underlying data structure behind a QAbstractItemModel, what do I do? How do I let the QAbstractItemModel know that data was inserted so that views connected to it can be notified and updated?

    At first I thought I should have the underlying data structure somehow trigger its attached QAbstractItemModel to emit rowsAboutToBeInserted just before the underlying data is modified, and rowsInserted afterwards. Except, the documentation for these two signals contains the following note:

    > It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.

    Ok, so that means my own item models aren't allowed to signal that rows were inserted? I don't understand how this is useful, then...

    Then there is also insertRows, which I can't understand the purpose of. This doesn't seem to be what I want. This seems to be a way to insert (blank, I guess?) rows in the underlying data via the model interface, which isn't what I'm trying to do (nor can I conceive of any situation in which this would be done).

    I have data stored in a class. The data changes and an element is inserted. So how do I ultimately cause the attached view to reflect the change, since I'm not allowed to call rowsInserted()?
    Last edited by JasonC; 5th March 2015 at 06:21.

Similar Threads

  1. How to make QAbstractItemModel 's data checkable
    By nifei in forum Qt Programming
    Replies: 12
    Last Post: 1st April 2013, 19:52
  2. Replies: 4
    Last Post: 28th September 2012, 18:19
  3. Data from model not inserted in QTableView
    By schmimona in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2011, 05:16
  4. How to fill an inserted column with data?
    By croo in forum Qt Programming
    Replies: 3
    Last Post: 12th December 2010, 19:58
  5. Replies: 4
    Last Post: 4th September 2009, 08:33

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