From dd5cfe2fae4199c0cdb15d4c761ddde69efb1b7b Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Fri, 23 Jun 2023 15:26:55 +0200 Subject: [PATCH] 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. --- src/nimqml/private/dotherside.nim | 1 + src/nimqml/private/qobject.nim | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nimqml/private/dotherside.nim b/src/nimqml/private/dotherside.nim index d9721dd..96e9036 100644 --- a/src/nimqml/private/dotherside.nim +++ b/src/nimqml/private/dotherside.nim @@ -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 diff --git a/src/nimqml/private/qobject.nim b/src/nimqml/private/qobject.nim index c076d35..02565d1 100644 --- a/src/nimqml/private/qobject.nim +++ b/src/nimqml/private/qobject.nim @@ -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 =