Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Insert item into model displayed with ListView QML component
Forum Updated to NodeBB v4.3 + New Features

Insert item into model displayed with ListView QML component

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 418 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cristeab
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved