diff --git a/src/nimqml.nim b/src/nimqml.nim index dc0d9f7..203feeb 100644 --- a/src/nimqml.nim +++ b/src/nimqml.nim @@ -17,6 +17,7 @@ include private/qmetaobject.nim include private/qvariant.nim include private/qobject.nim include private/qqmlapplicationengine.nim +include private/qapplication.nim #include private.nimqmltypes #var qobjectRegistry = initTable[ptr QObjectObj, bool]() #include private/qvariant.nim diff --git a/src/private/dotherside.nim b/src/private/dotherside.nim index 6e9289d..51b50f1 100644 --- a/src/private/dotherside.nim +++ b/src/private/dotherside.nim @@ -46,6 +46,12 @@ type proc resetToNil*[T](x: var T) = x = nil.pointer.T proc isNil*[T](x: T): bool = x.pointer == nil +# QApplication +proc dos_qapplication_create() {.cdecl, importc.} +proc dos_qapplication_exec() {.cdecl, importc.} +proc dos_qapplication_quit() {.cdecl, importc.} +proc dos_qapplication_delete() {.cdecl, importc.} + # QQmlContext proc dos_qqmlcontext_setcontextproperty(context: DosQQmlContext, propertyName: cstring, propertyValue: DosQVariant) {.cdecl, importc.} diff --git a/src/private/nimqmltypes.nim b/src/private/nimqmltypes.nim index 76f6931..62a11da 100644 --- a/src/private/nimqmltypes.nim +++ b/src/private/nimqmltypes.nim @@ -11,6 +11,10 @@ type ## A QQmlApplicationEngine vptr: DosQQmlApplicationEngine + QApplication = ref object of RootObj ## \ + ## A QApplication + deleted: bool + QtItemFlag* {.pure.} = enum ## \ ## Item flags ## diff --git a/src/private/qapplication.nim b/src/private/qapplication.nim index cb2713a..53e5b59 100644 --- a/src/private/qapplication.nim +++ b/src/private/qapplication.nim @@ -1,10 +1,5 @@ -proc dos_qapplication_create() {.cdecl, importc.} -proc dos_qapplication_exec() {.cdecl, importc.} -proc dos_qapplication_quit() {.cdecl, importc.} -proc dos_qapplication_delete() {.cdecl, importc.} - -proc create*(application: QApplication) = - ## Create a new QApplication +proc setup*(application: QApplication) = + ## Setup a new QApplication dos_qapplication_create() application.deleted = false @@ -18,12 +13,13 @@ proc quit*(application: QApplication) = proc delete*(application: QApplication) = ## Delete the given QApplication - if not application.deleted: - debugMsg("QApplication", "delete") - dos_qapplication_delete() - application.deleted = true + if application.deleted: + return + debugMsg("QApplication", "delete") + dos_qapplication_delete() + application.deleted = true proc newQApplication*(): QApplication = ## Return a new QApplication new(result, delete) - result.create() + result.setup()