diff --git a/Nim/Examples/HelloWorld/main.nim b/Nim/Examples/HelloWorld/main.nim index 897a160..a0bc25f 100644 --- a/Nim/Examples/HelloWorld/main.nim +++ b/Nim/Examples/HelloWorld/main.nim @@ -3,12 +3,10 @@ import macros import typeinfo proc mainProc() = - var app: QApplication - app.create() + var app = newQApplication() defer: app.delete() - var engine: QQmlApplicationEngine - engine.create() + var engine = newQQmlApplicationEngine() defer: engine.delete() engine.load("main.qml") @@ -17,3 +15,4 @@ proc mainProc() = when isMainModule: mainProc() +GC_fullcollect() diff --git a/Nim/Examples/QtObjectMacro/Contact.nim b/Nim/Examples/QtObjectMacro/Contact.nim index 7b9c79e..e404895 100644 --- a/Nim/Examples/QtObjectMacro/Contact.nim +++ b/Nim/Examples/QtObjectMacro/Contact.nim @@ -6,20 +6,24 @@ QtObject: type Contact* = ref object of QObject m_name: string - template newContact*(): Contact = - var result = Contact(m_name: "initialName") - result.create - result - - method getName*(contact: Contact): string {.slot.} = - result = contact.m_name + proc delete(self: Contact) = + var qobject = self.QObject + qobject.delete() - method nameChanged*(contact: Contact) {.signal.} + proc newContact*(): Contact = + new(result, delete) + result.m_name = "InitialName" + result.create - method setName*(contact: Contact, name: string) {.slot.} = - if contact.m_name != name: - contact.m_name = name - contact.nameChanged() + method getName*(self: Contact): string {.slot.} = + result = self.m_name + + method nameChanged*(self: Contact) {.signal.} + + method setName*(self: Contact, name: string) {.slot.} = + if self.m_name != name: + self.m_name = name + self.nameChanged() QtProperty[string] name: read = getName diff --git a/Nim/Examples/QtObjectMacro/main.nim b/Nim/Examples/QtObjectMacro/main.nim index 9c45926..ba4ea02 100644 --- a/Nim/Examples/QtObjectMacro/main.nim +++ b/Nim/Examples/QtObjectMacro/main.nim @@ -2,23 +2,19 @@ import NimQml import Contact proc mainProc() = - var app: QApplication - app.create() + var app = newQApplication() defer: app.delete() var contact = newContact() defer: contact.delete() - var engine: QQmlApplicationEngine - engine.create() + var engine = newQQmlApplicationEngine() defer: engine.delete() - var variant: QVariant - variant.create(contact) + var variant = newQVariant(contact) defer: variant.delete() - var rootContext: QQmlContext = engine.rootContext() - rootContext.setContextProperty("contact", variant) + engine.rootContext.setContextProperty("contact", variant) engine.load("main.qml") app.exec() diff --git a/Nim/Examples/SimpleData/main.nim b/Nim/Examples/SimpleData/main.nim index 622d645..2022850 100644 --- a/Nim/Examples/SimpleData/main.nim +++ b/Nim/Examples/SimpleData/main.nim @@ -3,12 +3,10 @@ import macros import typeinfo proc mainProc() = - var app: QApplication - app.create() + var app = newQApplication() defer: app.delete() - var engine: QQmlApplicationEngine - engine.create() + var engine = newQQmlApplicationEngine() defer: engine.delete() var qVar1 = newQVariant(10) @@ -23,10 +21,10 @@ proc mainProc() = engine.rootContext.setContextProperty("qVar1", qVar1) engine.rootContext.setContextProperty("qVar2", qVar2) engine.rootContext.setContextProperty("qVar3", qVar2) - engine.load("main.qml") app.exec() when isMainModule: mainProc() +GC_fullcollect() diff --git a/Nim/Examples/SlotsAndProperties/main.nim b/Nim/Examples/SlotsAndProperties/main.nim index 261eeb1..98e8cef 100644 --- a/Nim/Examples/SlotsAndProperties/main.nim +++ b/Nim/Examples/SlotsAndProperties/main.nim @@ -2,25 +2,23 @@ import NimQml import Contact proc mainProc() = - var app: QApplication - app.create() + var app = newQApplication() defer: app.delete() var contact = newContact() defer: contact.delete() - var engine: QQmlApplicationEngine - engine.create() + var engine = newQQmlApplicationEngine() defer: engine.delete() var variant = newQVariant(contact) defer: variant.delete() - var rootContext: QQmlContext = engine.rootContext() - rootContext.setContextProperty("contact", variant) + engine.rootContext.setContextProperty("contact", variant) engine.load("main.qml") app.exec() when isMainModule: mainProc() +GC_fullcollect()