我有一個從QAbstractListModel
分類的模型,它有一個QList
來維護包含QDateTime
的數據,該數據用於維護此列表。我必須將這些數據保留一小時,即舊數據將從列表中刪除。這基本上是FIFO列表。我有一個代理模型(QSortFilterProxyModel
的子類)來對數據進行排序。只要數據發生變化,代理模型就會丟失索引並顯示未過濾的數據。以下是執行此操作的代碼片段。QSortFilterProxyModel崩潰應用程序
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), 0, 1); //we are prepending
m_entries.prepend(e);
endInsertRows();
emit layoutChanged();
這似乎解決了這個問題。但是,如果在視圖(QTreeView
)上選擇了某些內容,那麼應用程序在某些時候會崩潰並出現大量這些錯誤消息。上的調試器
QSortFilterProxyModel: index from wrong model passed to mapFromSource
QSortFilterProxyModel: index from wrong model passed to mapFromSource
QSortFilterProxyModel: index from wrong model passed to mapFromSource
堆棧跟蹤顯示mouseSelectEvent
和其它功能,這需要QModelIndex
。
對不起,長期以來的問題。有人可以幫助解決這個問題嗎?
謝謝。
你似乎有一個樹模型。我認爲你需要爲beginInsertRows提供一個有效的父索引。或者至少這是一個猜測。 – user2672165
你能告訴我們你的QAbstractListModel和QSortFilterProxyModel的子類嗎?或者至少是違規的方法? –
@ user2672165我正在使用'QAbstractListModel'作爲基礎模型。 – ramtheconqueror