Insert item into model displayed with ListView QML component
-
Hi
I have a simple model shown in a ListView The model is actually a vector of messages that should appear in the list. This is how I try currently to insert a new message:
void MessagesModel::insertMessage(Message *newMsg) { QMutexLocker locker(&_messagesMutex); int rowPos = _messages.count(); //emit layoutAboutToBeChanged(); beginInsertRows(QModelIndex(), rowPos, rowPos); _messages.push_back(newMsg); locker.unlock(); //emit layoutChanged(); endInsertRows(); }
However, when I try to insert a new message the entire application blocks. If I use the commented lines instead (emit layoutAboutToBeChanged(), etc) the message is inserted but the item height in the ListView is not correctly detected and in some cases I get overlapped items (each message contains text, but the number of lines vary). Could someone explain what I am doing wrong and suggest a solution ?
thanks
Bogdan