[Development] QAbstractItemModel's meta-object got changed in QtQuick

Axel Spoerl axel.spoerl at qt.io
Tue Aug 15 10:05:05 CEST 2023


Hi Songziming,

Thanks for sharing.
The file system model is stack allocated after the application and the qml engine. So it’s deleted before them, when main() goes out of scope. The QML engine shutdown still finds a (stale) QObject and tries to disconnect signals from it, hence the warnings.

Allocating the model on the heap solves the issue. If parented to the engine, no manual deletion is necessary.

Brgds
Axel


On 15 Aug 2023, at 08:45, Ziming Song <s.ziming at hotmail.com> wrote:

Hi,

I create the custom model object in main function on stack. Model is instantiated after QQmlApplicationEngine, and is deleted before QQmlApplicationEngine. During custom model’s destruction, QItemSelectionModelPrivate::initModel(NULL) is called.

I also tested QFileSystemModel, which also reports signals not found.

Bug reported: https://bugreports.qt.io/browse/QTBUG-116056

Thanks
songziming

发件人: Axel Spoerl<mailto:axel.spoerl at qt.io>
发送时间: 2023年8月14日 21:26
收件人: Ziming Song<mailto:s.ziming at hotmail.com>
抄送: development at qt-project.org<mailto:development at qt-project.org>
主题: Re: [Development] QAbstractItemModel's meta-object got changed in QtQuick

Hi,

The meta object doesn’t change during execution. The messages probably mean, that upon app close, the custom class (inheriting from QObject) is already deleted. Only a QObject is left, which is what className() correctly reports.

Maybe throw a qDebug() in the custom class destructor, to check if it is reached too early. I personally haven’t seen error logs of that kind. It doesn’t seem right that the custom class gets deleted, with its connections still being reported as active. Unless there is a bug in the custom class implementation, I suggest to file a bug report with a minimal reproducer.

Cheers
Axel


On 14 Aug 2023, at 15:06, Ziming Song <s.ziming at hotmail.com<mailto:s.ziming at hotmail.com>> wrote:

Hi,

I’m playing with QtQuick TreeView with custom QAbstractItemModel in C++. The program runs fine, except some error logs when program exits:

qt.core.qobject.connect: QObject::disconnect: No such signal QObject::rowsAboutToBeRemoved(QModelIndex,int,int)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::columnsAboutToBeRemoved(QModelIndex,int,int)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::rowsAboutToBeInserted(QModelIndex,int,int)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::columnsAboutToBeInserted(QModelIndex,int,int)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::rowsMoved(QModelIndex,int,int,QModelIndex,int)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::columnsMoved(QModelIndex,int,int,QModelIndex,int)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::layoutAboutToBeChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::layoutChanged(QList<QPersistentModelIndex>,QAbstractItemModel::LayoutChangeHint)
qt.core.qobject.connect: QObject::disconnect: No such signal QObject::modelReset()

This is what I found.

Error messages come from QItemSelectionModelPrivate::initModel, which is called (at least) twice, one during app start to set the model and connect some signals, one during app close to disconnect signals and set model to NULL.

At app starting, m->metaObject()->className() is correct (my custom model class name).

At app closing, m->metaObject() value changes, and m->metaObject()->className() is “QObject”, which doesn’t have those signals, thus the error message.

Can metaobject be modified during execution? If so, why?

Thanks in advance
songziming
--
Development mailing list
Development at qt-project.org<mailto:Development at qt-project.org>
https://lists.qt-project.org/listinfo/development

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20230815/0a98f1ef/attachment-0001.htm>


More information about the Development mailing list