Fixed examples
This commit is contained in:
parent
d0f01b092a
commit
3613bfea4e
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue