Results 1 to 4 of 4

Thread: QTreeView did not refresh data when dataChanged was emitted

  1. #1
    Join Date
    Dec 2018
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question QTreeView did not refresh data when dataChanged was emitted

    I have a very weird issue. Could anyone please help me out of this? Thanks in advance.

    I have a QTreeview which shows data from a socket and it uses a custom QAbstractItemModel; When data arrives, dataChanged is emitted. And in the data method of my item model, I qDebug log information. The socket runs in a separate thread.

    The weird thing is that if I set a breakpoint in the model's data method, then the method is hit and a cell of QTreeView is updated. But if there are no breakpoints in the data method, the method seems not to be called (no logging from qDebug) and the cell is not updated.

    I guess it's related to thread stuff but I don't know what it is exactly. Any help will be greatly appreciated.

  2. #2
    Join Date
    Dec 2018
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView did not refresh data when dataChanged was emitted

    Just found that it only failed to update sub-nodes. Do I need to update something?

    Quote Originally Posted by Adknocker View Post
    I have a very weird issue. Could anyone please help me out of this? Thanks in advance.

    I have a QTreeview which shows data from a socket and it uses a custom QAbstractItemModel; When data arrives, dataChanged is emitted. And in the data method of my item model, I qDebug log information. The socket runs in a separate thread.

    The weird thing is that if I set a breakpoint in the model's data method, then the method is hit and a cell of QTreeView is updated. But if there are no breakpoints in the data method, the method seems not to be called (no logging from qDebug) and the cell is not updated.

    I guess it's related to thread stuff but I don't know what it is exactly. Any help will be greatly appreciated.

  3. #3
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    425
    Thanked 57 Times in 53 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView did not refresh data when dataChanged was emitted

    Quote Originally Posted by Adknocker View Post
    Just found that it only failed to update sub-nodes. Do I need to update something?
    Do you emit dataChanged() for the sub-nodes correctly? Doesn't seem to be the case.
    When you're debugging, a breakpoint triggers a repaint ( since another window gets the focus etc.) and therefore the view is repainted.

  4. #4
    Join Date
    Dec 2018
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView did not refresh data when dataChanged was emitted

    Hi, ChristianEhrlicher. Thanks for your time. You are correct! the parents of the indexes emitted by dataChanged are incorrect. Just identified the root of the issue. Happy new year!!!

Similar Threads

  1. QTreeView: How to refresh the view?
    By Kira in forum Qt Programming
    Replies: 18
    Last Post: 30th November 2015, 23:11
  2. Get indices of rows where the signal dataChanged() was emitted
    By yannwilfried in forum Qt Programming
    Replies: 6
    Last Post: 8th August 2013, 09:19
  3. dataChanged, isDirty -- how to tell data was changed...
    By scott_hollen in forum Qt Programming
    Replies: 7
    Last Post: 1st October 2011, 17:31
  4. Replies: 3
    Last Post: 29th April 2011, 13:15
  5. refresh Qtreeview after removing row
    By doublelune in forum Qt Programming
    Replies: 4
    Last Post: 13th March 2008, 18:52

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.