Answer the question
In order to leave comments, you need to log in
Qt: QAbstractItemModel is slow if I throw a layoutChanged() signal. What is the problem?
I have inherited from QAbstractItemModel and am using this model in TableView in QML.
I am trying to remove an element:
bool DownloadListModel::removeDownloadById(const QString &id)
{
DownloadFile* download = getDownloadById(id);
int index = getDownloadIndex(download);
if (download) {
beginRemoveRows(QModelIndex(),index,index);
_downloadsList.removeOne(download);
_downloadsMap.remove(id);
download->deleteLater();
_db->deleteDownload(id);
endRemoveRows();
return true;
}
return false;
}
bool DownloadListModel::removeDownloadById(const QString &id)
{
DownloadFile* download = getDownloadById(id);
int index = getDownloadIndex(download);
if (download) {
emit layoutAboutToBeChanged();
beginRemoveRows(QModelIndex(),index,index);
_downloadsList.removeOne(download);
_downloadsMap.remove(id);
download->deleteLater();
_db->deleteDownload(id);
endRemoveRows();
emit layoutChanged();
return true;
}
return false;
}
Answer the question
In order to leave comments, you need to log in
It's hard to say what works slowly without seeing all the code.
To begin with, I would advise you to go through the profiler + provide a link to the code if possible.
In general, a somewhat strange approach in my opinion.
Why is removeRows/removeColumns and their insert antagonists not used?
If you really want removeById, why not display it as an adapter?
It is somewhat easier, in my opinion, to use the capabilities of the interface of the standard model to the maximum.
Plus how is the index calculated and where are the dataChanged signals? This is probably why you use signaling for layout. Because without sending dataChanged, you should not hope for the correct display or selection.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question