Fixed. This actually seems to be a bug in Qt. When the root of an QTreeView is changed, the QTreeView::scrollContentsBy method is called if the view has been scrolled down. And in the body of this method, we have the following line:
const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight;
sizeHintForRow(0) requests the size of row 0, which does not exist in the case of empty lists, triggering the crash.
The workaround consists in scrolling back to the top whenever the root item of the list view is changed.
Fixed. This actually seems to be a bug in Qt. When the root of an QTreeView is changed, the QTreeView: :scrollContents By method is called if the view has been scrolled down. And in the body of this method, we have the following line:
const int itemHeight = d->defaultItemH eight <= 0 ? sizeHintForRow(0) : d->defaultItemH eight;
sizeHintForRow(0) requests the size of row 0, which does not exist in the case of empty lists, triggering the crash.
The workaround consists in scrolling back to the top whenever the root item of the list view is changed.