相关疑难解决方法(0)

在QTreeView中插入和删除行

美好的一天,我有一个继承自QAbstractItemModel的基本模型,还有一些不时通知该模型的后台线程,在示例中,插入行实现了这样的功能

bool TreeModel::insertRows(int position, int rows, const QModelIndex &parent)
{
    TreeItem *parentItem = getItem(parent);
    bool success;

    beginInsertRows(parent, position, position + rows - 1);
    success = parentItem->insertChildren(position, rows, rootItem->columnCount());
    endInsertRows();

    return success;
} 
Run Code Online (Sandbox Code Playgroud)

但是我不能这样做,因为我的模型是单个的,它使用4个视图,所以我是这样实现插入的:

void notifyEventImpl(file_item_type *sender,helper<ITEM_ACTION_ADDED>)
        {
            base_class::setSize(file_item_type::size()+sender->size());         
            m_listDirectory.push_back(sender);
            file_item_type::filesystem_type::s_notify.insert(this); // notify my model
        } 
Run Code Online (Sandbox Code Playgroud)

s_notify有实现的类在哪里:

 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*)) ));
        }
Run Code Online (Sandbox Code Playgroud)

鉴于此,我将调用该方法:

void FileItemModel::insertItem(void *it)
{ …
Run Code Online (Sandbox Code Playgroud)

c++ qt qtreeview qabstractitemmodel

4
推荐指数
1
解决办法
7847
查看次数

两个线程可以同时从同一个QList读取吗?

相当新的线程,我有这个线程在它们之间共享的QList.它们都有自己可以处理的空间,GUI(模型/视图)不断访问此列表.然后我得到这个指向QDataList.size()的崩溃.调试并没有真正帮助我,因为我从未遇到过这个问题,如果我单步执行代码,当我正在尝试qList崩溃时,没有可用的信息.

所以,我的问题是:是否有可能获得Qlists大小并同时读取对象?列表中的对象是线程安全的,不能同时由不同的线程读/写.

获取"0xC0000005:访问冲突读取位置0xfeeefefa".它指向我:qlist.h中的inline int size()const

我走过调用堆栈,发现这个:

QtCored4.dll!QListData::size()  Line 98 + 0x11 bytes    C++
QtNetworkd4.dll!QList<enum QNetworkReplyImplPrivate::InternalNotifications>::size()  Line 137 + 0x10 bytes  C++
QtNetworkd4.dll!QNetworkReplyImplPrivate::resumeNotificationHandling()  Line 444 + 0xe bytes    C++
QtNetworkd4.dll!QNetworkReplyImplPrivate::finished()  Line 797  C++
QtNetworkd4.dll!QNetworkAccessBackend::finished()  Line 313 C++
QtNetworkd4.dll!QNetworkAccessHttpBackend::replyFinished()  Line 739    C++
QtNetworkd4.dll!QNetworkAccessHttpBackend::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a)  Line 86 + 0x8 bytes    C++
QtCored4.dll!QMetaCallEvent::placeMetaCall(QObject * object)  Line 525 + 0x1d bytes C++
QtCored4.dll!QObject::event(QEvent * e)  Line 1195 + 0x14 bytes C++
QtGuid4.dll!QApplicationPrivate::notify_helper(QObject * receiver, QEvent * …
Run Code Online (Sandbox Code Playgroud)

c++ qt qthread qlist

3
推荐指数
1
解决办法
7939
查看次数

标签 统计

c++ ×2

qt ×2

qabstractitemmodel ×1

qlist ×1

qthread ×1

qtreeview ×1