Results 1 to 13 of 13

Thread: How to inform a Model/TableView that some data changed?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to inform a Model/TableView that some data changed?

    Ok I'll try to explain better:

    I have a char array that's the underlying data structure.
    I've subclassed QAbstractTableModel to act as the model.
    I've added a Table view like this:



    I have a timer that increments the underlying data, in its [0,0] position.
    Right now, when I select a cell, or interact in some way with the table, then the cell's value is updated, because the table view somehow calls the model's data() method.
    What I want to achieve is on each timer event, twice per second, the view updates the cell's values on the screen.
    So please tell me what object should be the sender, and what signal of it, and what object should be the receiver, and what slot of it.
    Or if I can achieve this with just a method call, instead of signals.

    Edit:
    I tried emitting layoutChanged() from the model, which works ok.
    But I'm setting a timer with 0 msec timout and all I get is the signal emitted no more than 30 times per second, I need something faster.

    Can't I just inform the view to update exactly the cell I know has changed?
    I tried with the signal QAbstractItemModel::dataChanged, but I can't emit it from a QAbstractTableModel subclass, although it should inherit QAbstractItemModel's members, so what, aren't signals inherited?
    Last edited by Petruza; 20th June 2010 at 20:30.

  2. #2
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to inform a Model/TableView that some data changed?

    What about this?
    void QAbstractItemModel::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) [signal]

    This signal is emitted whenever the data in an existing item changes.

    If the items are of the same parent, the affected ones are those between topLeft and bottomRight inclusive
    Then connect the signal to a slot where you view->show to refresh it?

    How are you setting the model to the data? Seems like all you should have to do is re-run that code on the timer and the model/view signal slot will do what you want without further code.
    Last edited by waynew; 20th June 2010 at 20:39.

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

    moviemax (24th June 2011)

  4. #3
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: How to inform a Model/TableView that some data changed?

    Quote Originally Posted by Petruza View Post
    Can't I just inform the view to update exactly the cell I know has changed?
    I tried with the signal QAbstractItemModel::dataChanged, but I can't emit it from a QAbstractTableModel subclass, although it should inherit QAbstractItemModel's members, so what, aren't signals inherited?
    You should emit QAbstractItemModel::dataChanged() signal inside QAbstractItemModel::setData() function.

    So, how do you implement QAbstractItemModel::setData() function in your custom model?

    For more informations about model subclassing, you can look at Model Subclassing Reference.
    Last edited by saa7_go; 24th July 2010 at 08:12. Reason: updated contents

Similar Threads

  1. TableView/Model Display Question
    By SixDegrees in forum Qt Programming
    Replies: 9
    Last Post: 27th August 2010, 09:06
  2. Replies: 1
    Last Post: 1st February 2010, 18:42
  3. tableview model view problem
    By skuda in forum Qt Programming
    Replies: 5
    Last Post: 3rd December 2007, 14:02
  4. getting data from tableView
    By mkarakaplan in forum Newbie
    Replies: 1
    Last Post: 7th November 2007, 09:51
  5. Informing a model its data has changed
    By saknopper in forum Newbie
    Replies: 3
    Last Post: 17th January 2007, 19:58

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.