PDA

View Full Version : QTreeView did not refresh data when dataChanged was emitted



Adknocker
29th December 2018, 06:03
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.

Adknocker
29th December 2018, 15:40
Just found that it only failed to update sub-nodes. Do I need to update something?


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.

ChristianEhrlicher
29th December 2018, 16:05
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.

Adknocker
30th December 2018, 01:10
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!!!