Random crash in QAbstractListModel
-
Hi all,
I am dealing with a crash that I could not solved and that I have been dealing with for weeks now.
You are my last chances since me and couple other person can not find what is going on.Here is what i have ( only what is interesting )
class MyList : public QAbstractListModel { public: void addObject( const std::shared_ptr< MyObject >& object ) { if( ! _list.contains( object ) ) { QQmlEngine::setObjectOwnership( object.get(), QQmlEngine::CppOwnership ); beginInsertRows( QModelIndex(), rowCount(), rowCount() ); _list.push_back( object ); endInsertRows(); } } void removeObject( const std::shared_ptr< MyObject >& object ) { const int index = _list.indexOf( object ); if( index != -1 ) { beginRemoveRows( QModelIndex(), index, index ); _list.removeAt( index ); endRemoveRows(); } } Q_INVOKABLE MyObject* getObjectAt( const int index ) { return _list.value( index ).get(); } private: QList< std::shared_ptr< MyObject > > _list; };
The QML does not uses roles. When used, it will call getObjectAt and deal directly with it.
From time to time, i will get this crash:
0 libQt5Core_debug.5.dylib 0x000000010bfc0f73 QObjectPrivate::isSignalConnected(unsigned int) const + 67
1 libQt5Core_debug.5.dylib 0x000000010c39a8d4 QMetaObject::activate(QObject*, int, int, void**) + 68
2 libQt5Core_debug.5.dylib 0x000000010c39a87d QMetaObject::activate(QObject*, QMetaObject const*, int, void**) + 61
3 libQt5Qml_debug.5.dylib 0x000000010b49a71b QQmlDelegateModelItem::modelIndexChanged() + 43 (moc_qqmldelegatemodel_p_p.cpp:164)
4 libQt5Qml_debug.5.dylib 0x000000010b46754e QQmlDelegateModelItem::setModelIndex(int) + 30 (qqmldelegatemodel_p_p.h:121)
5 libQt5Qml_debug.5.dylib 0x000000010b45775e QQmlDelegateModel::_q_itemsRemoved(int, int) + 222 (qqmldelegatemodel.cpp:1339)
6 libQt5Qml_debug.5.dylib 0x000000010b45d10c QQmlDelegateModel::_q_rowsRemoved(QModelIndex const&, int, int) + 124 (qqmldelegatemodel.cpp:1497)
7 libQt5Qml_debug.5.dylib 0x000000010b497f03 QQmlDelegateModel::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 435 (moc_qqmldelegatemodel_p.cpp:200)
8 libQt5Qml_debug.5.dylib 0x000000010b498627 QQmlDelegateModel::qt_metacall(QMetaObject::Call, int, void**) + 135 (moc_qqmldelegatemodel_p.cpp:294)
9 libQt5Core_debug.5.dylib 0x000000010c34bed5 QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) + 165
10 libQt5Core_debug.5.dylib 0x000000010c39b59e QMetaObject::activate(QObject*, int, int, void**) + 3342
11 libQt5Core_debug.5.dylib 0x000000010c39a87d QMetaObject::activate(QObject*, QMetaObject const*, int, void**) + 61
12 libQt5Core_debug.5.dylib 0x000000010c46608b QAbstractItemModel::rowsRemoved(QModelIndex const&, int, int, QAbstractItemModel::QPrivateSignal) + 107
13 libQt5Core_debug.5.dylib 0x000000010c2b97a9 QAbstractItemModel::endRemoveRows() + 89I can not explain it, my objects seems to be still valid..