some comments
This commit is contained in:
parent
75a7fa4fcf
commit
f5eed607bd
|
@ -13,6 +13,8 @@ var signalHandler: SignalCallback = proc(p0: cstring): void =
|
|||
|
||||
tearDownForeignThreadGc()
|
||||
|
||||
|
||||
# Probably all QT classes will look like this:
|
||||
QtObject:
|
||||
type ApplicationLogic* = ref object of QObject
|
||||
app: QApplication
|
||||
|
@ -52,6 +54,8 @@ QtObject:
|
|||
proc onExitTriggered(self: ApplicationLogic) {.slot.} =
|
||||
self.app.quit
|
||||
|
||||
|
||||
# Accesors
|
||||
proc callResult*(self: ApplicationLogic): string {.slot.} =
|
||||
result = self.callResult
|
||||
|
||||
|
@ -64,6 +68,7 @@ QtObject:
|
|||
|
||||
proc `callResult=`*(self: ApplicationLogic, callResult: string) = self.setCallResult(callResult)
|
||||
|
||||
# Binding between a QML variable and accesors is done here
|
||||
QtProperty[string] callResult:
|
||||
read = callResult
|
||||
write = setCallResult
|
||||
|
@ -91,3 +96,6 @@ QtObject:
|
|||
read = accountResult
|
||||
write = setAccountResult
|
||||
notify = callResultChanged
|
||||
|
||||
# This class has the metaObject property available which lets
|
||||
# access all the QProperties which are stored as QVariants
|
|
@ -2,20 +2,31 @@ import NimQml
|
|||
import applicationLogic
|
||||
|
||||
proc mainProc() =
|
||||
|
||||
# From QT docs:
|
||||
# For any GUI application using Qt, there is precisely one QApplication object,
|
||||
# no matter whether the application has 0, 1, 2 or more windows at any given time.
|
||||
# For non-QWidget based Qt applications, use QGuiApplication instead, as it does
|
||||
# not depend on the QtWidgets library. Use QCoreApplication for non GUI apps
|
||||
var app = newQApplication()
|
||||
defer: app.delete()
|
||||
|
||||
let logic = newApplicationLogic(app)
|
||||
defer: logic.delete
|
||||
defer: app.delete() # Defer will run this just before mainProc() function ends
|
||||
|
||||
|
||||
var engine = newQQmlApplicationEngine()
|
||||
defer: engine.delete()
|
||||
|
||||
|
||||
let logic = newApplicationLogic(app)
|
||||
defer: logic.delete
|
||||
|
||||
let logicVariant = newQVariant(logic)
|
||||
defer: logicVariant.delete
|
||||
|
||||
engine.setRootContextProperty("logic", logicVariant)
|
||||
engine.load("main.qml")
|
||||
|
||||
# Qt main event loop is entered here
|
||||
# The termination of the loop will be performed when exit() or quit() is called
|
||||
app.exec()
|
||||
|
||||
when isMainModule:
|
||||
|
|
Loading…
Reference in New Issue