Fixed examples
This commit is contained in:
parent
d0f01b092a
commit
3613bfea4e
|
@ -3,12 +3,10 @@ import macros
|
||||||
import typeinfo
|
import typeinfo
|
||||||
|
|
||||||
proc mainProc() =
|
proc mainProc() =
|
||||||
var app: QApplication
|
var app = newQApplication()
|
||||||
app.create()
|
|
||||||
defer: app.delete()
|
defer: app.delete()
|
||||||
|
|
||||||
var engine: QQmlApplicationEngine
|
var engine = newQQmlApplicationEngine()
|
||||||
engine.create()
|
|
||||||
defer: engine.delete()
|
defer: engine.delete()
|
||||||
|
|
||||||
engine.load("main.qml")
|
engine.load("main.qml")
|
||||||
|
@ -17,3 +15,4 @@ proc mainProc() =
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
mainProc()
|
mainProc()
|
||||||
|
|
||||||
|
GC_fullcollect()
|
||||||
|
|
|
@ -6,20 +6,24 @@ QtObject:
|
||||||
type Contact* = ref object of QObject
|
type Contact* = ref object of QObject
|
||||||
m_name: string
|
m_name: string
|
||||||
|
|
||||||
template newContact*(): Contact =
|
proc delete(self: Contact) =
|
||||||
var result = Contact(m_name: "initialName")
|
var qobject = self.QObject
|
||||||
result.create
|
qobject.delete()
|
||||||
result
|
|
||||||
|
|
||||||
method getName*(contact: Contact): string {.slot.} =
|
|
||||||
result = contact.m_name
|
|
||||||
|
|
||||||
method nameChanged*(contact: Contact) {.signal.}
|
proc newContact*(): Contact =
|
||||||
|
new(result, delete)
|
||||||
|
result.m_name = "InitialName"
|
||||||
|
result.create
|
||||||
|
|
||||||
method setName*(contact: Contact, name: string) {.slot.} =
|
method getName*(self: Contact): string {.slot.} =
|
||||||
if contact.m_name != name:
|
result = self.m_name
|
||||||
contact.m_name = name
|
|
||||||
contact.nameChanged()
|
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:
|
QtProperty[string] name:
|
||||||
read = getName
|
read = getName
|
||||||
|
|
|
@ -2,23 +2,19 @@ import NimQml
|
||||||
import Contact
|
import Contact
|
||||||
|
|
||||||
proc mainProc() =
|
proc mainProc() =
|
||||||
var app: QApplication
|
var app = newQApplication()
|
||||||
app.create()
|
|
||||||
defer: app.delete()
|
defer: app.delete()
|
||||||
|
|
||||||
var contact = newContact()
|
var contact = newContact()
|
||||||
defer: contact.delete()
|
defer: contact.delete()
|
||||||
|
|
||||||
var engine: QQmlApplicationEngine
|
var engine = newQQmlApplicationEngine()
|
||||||
engine.create()
|
|
||||||
defer: engine.delete()
|
defer: engine.delete()
|
||||||
|
|
||||||
var variant: QVariant
|
var variant = newQVariant(contact)
|
||||||
variant.create(contact)
|
|
||||||
defer: variant.delete()
|
defer: variant.delete()
|
||||||
|
|
||||||
var rootContext: QQmlContext = engine.rootContext()
|
engine.rootContext.setContextProperty("contact", variant)
|
||||||
rootContext.setContextProperty("contact", variant)
|
|
||||||
engine.load("main.qml")
|
engine.load("main.qml")
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,10 @@ import macros
|
||||||
import typeinfo
|
import typeinfo
|
||||||
|
|
||||||
proc mainProc() =
|
proc mainProc() =
|
||||||
var app: QApplication
|
var app = newQApplication()
|
||||||
app.create()
|
|
||||||
defer: app.delete()
|
defer: app.delete()
|
||||||
|
|
||||||
var engine: QQmlApplicationEngine
|
var engine = newQQmlApplicationEngine()
|
||||||
engine.create()
|
|
||||||
defer: engine.delete()
|
defer: engine.delete()
|
||||||
|
|
||||||
var qVar1 = newQVariant(10)
|
var qVar1 = newQVariant(10)
|
||||||
|
@ -23,10 +21,10 @@ proc mainProc() =
|
||||||
engine.rootContext.setContextProperty("qVar1", qVar1)
|
engine.rootContext.setContextProperty("qVar1", qVar1)
|
||||||
engine.rootContext.setContextProperty("qVar2", qVar2)
|
engine.rootContext.setContextProperty("qVar2", qVar2)
|
||||||
engine.rootContext.setContextProperty("qVar3", qVar2)
|
engine.rootContext.setContextProperty("qVar3", qVar2)
|
||||||
|
|
||||||
engine.load("main.qml")
|
engine.load("main.qml")
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
mainProc()
|
mainProc()
|
||||||
|
|
||||||
|
GC_fullcollect()
|
||||||
|
|
|
@ -2,25 +2,23 @@ import NimQml
|
||||||
import Contact
|
import Contact
|
||||||
|
|
||||||
proc mainProc() =
|
proc mainProc() =
|
||||||
var app: QApplication
|
var app = newQApplication()
|
||||||
app.create()
|
|
||||||
defer: app.delete()
|
defer: app.delete()
|
||||||
|
|
||||||
var contact = newContact()
|
var contact = newContact()
|
||||||
defer: contact.delete()
|
defer: contact.delete()
|
||||||
|
|
||||||
var engine: QQmlApplicationEngine
|
var engine = newQQmlApplicationEngine()
|
||||||
engine.create()
|
|
||||||
defer: engine.delete()
|
defer: engine.delete()
|
||||||
|
|
||||||
var variant = newQVariant(contact)
|
var variant = newQVariant(contact)
|
||||||
defer: variant.delete()
|
defer: variant.delete()
|
||||||
|
|
||||||
var rootContext: QQmlContext = engine.rootContext()
|
engine.rootContext.setContextProperty("contact", variant)
|
||||||
rootContext.setContextProperty("contact", variant)
|
|
||||||
engine.load("main.qml")
|
engine.load("main.qml")
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
mainProc()
|
mainProc()
|
||||||
|
|
||||||
|
GC_fullcollect()
|
||||||
|
|
Loading…
Reference in New Issue