Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert and delete rows in QTreeView
    primarykey
    data
    text
    <p>Good day, I Have base model inherited from QAbstractItemModel, and some background threads which notify this model from time to time, in examples the insertions rows implemens somthing like this </p> <pre><code>bool TreeModel::insertRows(int position, int rows, const QModelIndex &amp;parent) { TreeItem *parentItem = getItem(parent); bool success; beginInsertRows(parent, position, position + rows - 1); success = parentItem-&gt;insertChildren(position, rows, rootItem-&gt;columnCount()); endInsertRows(); return success; } </code></pre> <p>But I can't do it like this because my model is single which uses 4 views, I've implemented my insertion this way:</p> <pre><code>void notifyEventImpl(file_item_type *sender,helper&lt;ITEM_ACTION_ADDED&gt;) { base_class::setSize(file_item_type::size()+sender-&gt;size()); m_listDirectory.push_back(sender); file_item_type::filesystem_type::s_notify.insert(this); // notify my model } </code></pre> <p>Where <code>s_notify</code> is a class with implementation:</p> <pre><code> void Notifaer::dataChange(void * item){emit dataChanged(item);} void Notifaer::remove(void * item){emit removed(item);} void Notifaer::insert(void * item){emit inserted(item);} void Notifaer::push_back(const FileItemModel * model) { VERIFY(QObject::connect(this,SIGNAL(dataChanged(void*)),model,SLOT(dataChangeItem(void*)) )); VERIFY(QObject::connect(this,SIGNAL(removed(void*)),model,SLOT(removeItem(void*)) )); VERIFY(QObject::connect(this,SIGNAL(inserted(void*)),model,SLOT(insertItem(void*)) )); } </code></pre> <p>Given this, I invoke the method:</p> <pre><code>void FileItemModel::insertItem(void *it) { file_item_type *item = dynamic_cast&lt;file_item_type*&gt;(static_cast&lt;file_item_type*&gt;(it)); { QModelIndex index = createIndex(0,0,item); if (index.isValid()) { beginInsertRows(index, 0, item-&gt;childCount()-1); endInsertRows(); } } } void FileItemModel::removeItem(void *it) { file_item_type *item = static_cast&lt;file_item_type*&gt;(it); { QModelIndex index = createIndex(0,0,item); if (index.isValid()) { beginRemoveRows(index, 0, item-&gt;childCount()-1); endRemoveRows(); } } } </code></pre> <p>Remove rows works perfectly, but insert does not work. What's wrong in my implementation?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload