From f606ebdd725df35952d5029adecae8834493d3f6 Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Fri, 20 May 2022 16:31:56 +0200 Subject: [PATCH] Add `_id()` to `QObject` for debugging purposes --- src/lib/QtCore/QObject.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/QtCore/QObject.ts b/src/lib/QtCore/QObject.ts index d849e3a12..766007298 100644 --- a/src/lib/QtCore/QObject.ts +++ b/src/lib/QtCore/QObject.ts @@ -7,6 +7,8 @@ import { TimerType } from '../QtEnums/TimerType'; import { wrapperCache } from '../core/WrapperCache'; export class QObject extends EventWidget { + private __id: number; + constructor(nativeElementOrParent?: NativeElement | QObject) { let native: NativeElement; if (checkIfNativeElement(nativeElementOrParent)) { @@ -18,10 +20,22 @@ export class QObject extends Ev native = new addon.QObject(); } super(native); - + this.__id = native.__id__(); wrapperCache.store(this); } + /** + * Get an ID identifying the underlying C++ object. + * + * This can be useful when debugging memory problems with help from + * `setLogCreateQObject()` and `setLogDestroyQObject()`. The number is + * hash of the memory address of the C++ object. + * + * @return a unique number which is valid for the lifetime of the C++ object. + */ + _id(): number { + return this.__id; + } inherits(className: string): boolean { return this.native.inherits(className); }