fix: replace `dos_qobject_delete` with `dos_qobject_deleteLater`

Previously, the code used `dos_qobject_delete`, which could potentially
cause problems if the object was still in use, especially if there were
pending events for the object in the event queue. This could lead to
unexpected crashes.

Also, `dos_qobject_delete` disconnects just before the QObject is
deleted, leading to clients not being notified about deletion.

`dos_qobject_deleteLater` ensures that the QObject is not deleted until
all its pending events are processed and also ensures that all clients
are notified about its deletion.
This commit is contained in:
Patryk Osmaczko 2023-06-23 15:26:55 +02:00 committed by osmaczko
parent 75cb0ace7f
commit dd5cfe2fae
2 changed files with 2 additions and 1 deletions

View File

@ -204,6 +204,7 @@ proc dos_qobject_objectName(qobject: DosQObject): cstring {.cdecl, dynlib: dynLi
proc dos_qobject_setObjectName(qobject: DosQObject, name: cstring) {.cdecl, dynlib: dynLibName, importc.}
proc dos_qobject_signal_emit(qobject: DosQObject, signalName: cstring, argumentsCount: cint, arguments: ptr DosQVariantArray) {.cdecl, dynlib: dynLibName, importc.}
proc dos_qobject_delete(qobject: DosQObject) {.cdecl, dynlib: dynLibName, importc.}
proc dos_qobject_deleteLater(qobject: DosQObject) {.cdecl, dynlib: dynLibName, importc.}
proc dos_qobject_signal_connect(sender: DosQObject, signalName: cstring, receiver: DosQObject, slot: cstring, signalType: cint) {.cdecl, dynlib: dynLibName, importc.}
# QAbstractItemModel

View File

@ -61,7 +61,7 @@ proc delete*(self: QObject) =
## Delete a QObject
if not self.owner or self.vptr.isNil:
return
dos_qobject_delete(self.vptr)
dos_qobject_deleteLater(self.vptr)
self.vptr.resetToNil
proc newQObject*(): QObject =