dotherside/Nim/main.nim

58 lines
1.5 KiB
Nim
Raw Normal View History

2014-12-08 12:55:09 +01:00
import NimQml
import macros
import typeinfo
2014-12-01 21:02:33 +01:00
type MyQObject = ref object of QObject
2014-12-01 21:02:33 +01:00
method myVoidSlot(myQObject: MyQObject) =
echo "MyQObject: myVoidSlot called"
myQObject.emit("intValueChanged", [])
method myIntSlot(myQObject: MyQObject, value: int) =
echo "MyQObject: myIntSlot called with arg ", $value
method myIntSlot2(myQObject: MyQObject, value: int): int =
echo "MyQObject: myIntSlot called with arg ", $value
return -10
method onSlotCalled(myQObject: MyQObject, slotName: string, args: openarray[QVariant]) =
case slotName:
of "myVoidSlot":
myQObject.myVoidSlot()
of "myIntSlot":
myQObject.myIntSlot(args[1].intVal)
of "myIntSlot2":
args[0].intVal = myQObject.myIntSlot2(args[1].intVal)
else:
discard()
proc mainProc() =
2014-12-01 21:02:33 +01:00
var app: QApplication
app.create()
finally: app.delete()
2014-12-08 12:55:09 +01:00
var myQObject = MyQObject()
2014-12-08 12:55:09 +01:00
myQObject.create()
finally: myQObject.delete()
myQObject.registerSlot("myVoidSlot", [QMetaType.Void])
myQObject.registerSlot("myIntSlot", [QMetaType.Void, QMetaType.Int])
myQObject.registerSlot("myIntSlot2", [QMetaType.Int, QMetaType.Int])
myQObject.registerSignal("intValueChanged", [QMetaType.Void])
2014-12-01 21:02:33 +01:00
var engine: QQmlApplicationEngine
engine.create()
finally: engine.delete()
2014-12-08 12:55:09 +01:00
var variant: QVariant
variant.create(myQObject)
finally: variant.delete()
2014-12-01 21:02:33 +01:00
2014-12-08 12:55:09 +01:00
var rootContext: QQmlContext = engine.rootContext()
rootContext.setContextProperty("myQObject", variant)
2014-12-08 12:55:09 +01:00
engine.load("main.qml")
app.exec()
when isMainModule:
mainProc()