mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-08-03 00:38:41 +02:00
[qt] delay objects deletion until next event loop
avoid warning messages when QML engine tries to evaluate an object that is already deleted
This commit is contained in:
parent
1663b86542
commit
d4c1ee6e83
1 changed files with 11 additions and 1 deletions
|
@ -21,6 +21,8 @@ class QObjectListModel(QtCore.QAbstractListModel):
|
|||
self.roles = QtCore.QAbstractListModel.roleNames(self)
|
||||
self.roles[self.ObjectRole] = b"object"
|
||||
|
||||
self.requestDeletion.connect(self.onRequestDeletion, QtCore.Qt.QueuedConnection)
|
||||
|
||||
def roleNames(self):
|
||||
return self.roles
|
||||
|
||||
|
@ -267,7 +269,10 @@ class QObjectListModel(QtCore.QAbstractListModel):
|
|||
def _dereferenceItem(self, item):
|
||||
# Ask for object deletion if parented to the model
|
||||
if item.parent() == self:
|
||||
item.deleteLater()
|
||||
# delay deletion until the next event loop
|
||||
# This avoids warnings when the QML engine tries to evaluate (but should not)
|
||||
# an object that has already been deleted
|
||||
self.requestDeletion.emit(item)
|
||||
|
||||
if not self._keyAttrName:
|
||||
return
|
||||
|
@ -277,9 +282,14 @@ class QObjectListModel(QtCore.QAbstractListModel):
|
|||
assert key in self._objectByKey
|
||||
del self._objectByKey[key]
|
||||
|
||||
def onRequestDeletion(self, item):
|
||||
item.deleteLater()
|
||||
|
||||
countChanged = QtCore.Signal()
|
||||
count = QtCore.Property(int, size, notify=countChanged)
|
||||
|
||||
requestDeletion = QtCore.Signal(QtCore.QObject)
|
||||
|
||||
|
||||
class QTypedObjectListModel(QObjectListModel):
|
||||
""" Typed QObjectListModel that exposes T properties as roles """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue