From f5eed607bdb5ac501e4f56937865e1dac82c038d Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Sun, 10 May 2020 19:24:06 -0400 Subject: [PATCH] some comments --- src/applicationLogic.nim | 8 ++++++++ src/nim_status_client.nim | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/applicationLogic.nim b/src/applicationLogic.nim index 3eeebe59d1..5e81f5ef1c 100644 --- a/src/applicationLogic.nim +++ b/src/applicationLogic.nim @@ -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 \ No newline at end of file diff --git a/src/nim_status_client.nim b/src/nim_status_client.nim index 649bb5017b..bbc5214c65 100644 --- a/src/nim_status_client.nim +++ b/src/nim_status_client.nim @@ -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: