some comments

This commit is contained in:
Richard Ramos 2020-05-10 19:24:06 -04:00
parent 75a7fa4fcf
commit f5eed607bd
2 changed files with 23 additions and 4 deletions

View File

@ -13,6 +13,8 @@ var signalHandler: SignalCallback = proc(p0: cstring): void =
tearDownForeignThreadGc() tearDownForeignThreadGc()
# Probably all QT classes will look like this:
QtObject: QtObject:
type ApplicationLogic* = ref object of QObject type ApplicationLogic* = ref object of QObject
app: QApplication app: QApplication
@ -52,6 +54,8 @@ QtObject:
proc onExitTriggered(self: ApplicationLogic) {.slot.} = proc onExitTriggered(self: ApplicationLogic) {.slot.} =
self.app.quit self.app.quit
# Accesors
proc callResult*(self: ApplicationLogic): string {.slot.} = proc callResult*(self: ApplicationLogic): string {.slot.} =
result = self.callResult result = self.callResult
@ -64,6 +68,7 @@ QtObject:
proc `callResult=`*(self: ApplicationLogic, callResult: string) = self.setCallResult(callResult) proc `callResult=`*(self: ApplicationLogic, callResult: string) = self.setCallResult(callResult)
# Binding between a QML variable and accesors is done here
QtProperty[string] callResult: QtProperty[string] callResult:
read = callResult read = callResult
write = setCallResult write = setCallResult
@ -91,3 +96,6 @@ QtObject:
read = accountResult read = accountResult
write = setAccountResult write = setAccountResult
notify = callResultChanged notify = callResultChanged
# This class has the metaObject property available which lets
# access all the QProperties which are stored as QVariants

View File

@ -2,20 +2,31 @@ import NimQml
import applicationLogic import applicationLogic
proc mainProc() = 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() var app = newQApplication()
defer: app.delete() defer: app.delete() # Defer will run this just before mainProc() function ends
let logic = newApplicationLogic(app)
defer: logic.delete
var engine = newQQmlApplicationEngine() var engine = newQQmlApplicationEngine()
defer: engine.delete() defer: engine.delete()
let logic = newApplicationLogic(app)
defer: logic.delete
let logicVariant = newQVariant(logic) let logicVariant = newQVariant(logic)
defer: logicVariant.delete defer: logicVariant.delete
engine.setRootContextProperty("logic", logicVariant) engine.setRootContextProperty("logic", logicVariant)
engine.load("main.qml") 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() app.exec()
when isMainModule: when isMainModule: