From 6a5f0ef32ef63b11258866f6208ccfbd43245fd3 Mon Sep 17 00:00:00 2001 From: Andrei Smirnov Date: Mon, 19 Jul 2021 12:20:35 +0300 Subject: [PATCH 1/2] feat: QGuiApplication supporting icon() and installEventFilter() methods as well as passing argc, argv --- src/nimqml/private/dotherside.nim | 4 +++- src/nimqml/private/qguiapplication.nim | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/nimqml/private/dotherside.nim b/src/nimqml/private/dotherside.nim index 1055211..8f65a0e 100644 --- a/src/nimqml/private/dotherside.nim +++ b/src/nimqml/private/dotherside.nim @@ -138,10 +138,12 @@ proc dos_qapplication_clipboard_setText(content: cstring) {.cdecl, dynlib: dynLi proc dos_qapplication_installEventFilter(engine: DosQQmlApplicationEngine) {.cdecl, dynlib: dynLibName, importc.} # QGuiApplication -proc dos_qguiapplication_create() {.cdecl, dynlib: dynLibName, importc.} +proc dos_qguiapplication_create(argc: cint, argv: cstringArray) {.cdecl, dynlib: dynLibName, importc.} proc dos_qguiapplication_exec() {.cdecl, dynlib: dynLibName, importc.} proc dos_qguiapplication_quit() {.cdecl, dynlib: dynLibName, importc.} +proc dos_qguiapplication_icon(filename: cstring) {.cdecl, dynlib: dynLibName, importc.} proc dos_qguiapplication_delete() {.cdecl, dynlib: dynLibName, importc.} +proc dos_qguiapplication_installEventFilter(engine: DosQQmlApplicationEngine) {.cdecl, dynlib: dynLibName, importc.} # QQmlContext proc dos_qqmlcontext_setcontextproperty(context: DosQQmlContext, propertyName: cstring, propertyValue: DosQVariant) {.cdecl, dynlib: dynLibName, importc.} diff --git a/src/nimqml/private/qguiapplication.nim b/src/nimqml/private/qguiapplication.nim index 8db82b2..39435b3 100644 --- a/src/nimqml/private/qguiapplication.nim +++ b/src/nimqml/private/qguiapplication.nim @@ -1,18 +1,32 @@ +import os + proc setup*(self: QGuiApplication) = - ## Setup a new QApplication - dos_qguiapplication_create() + ## Setup a new QGuiApplication + var argv = allocCStringArray([]) + argv[0] = getAppFilename().cstring + for argi in 1..paramCount(): + argv[argi] = paramStr(argi).cstring + + var argc = paramCount() + 1 + dos_qguiapplication_create(argc.cint, argv) self.deleted = false proc delete*(self: QGuiApplication) = - ## Delete the given QApplication + ## Delete the given QGuiApplication if self.deleted: return - debugMsg("QApplication", "delete") + debugMsg("QGuiApplication", "delete") dos_qguiapplication_delete() self.deleted = true +proc icon*(application: QGuiApplication, filename: string) = + dos_qguiapplication_icon(filename.cstring) + +proc installEventFilter*(application: QGuiApplication, engine: QQmlApplicationEngine) = + dos_qguiapplication_installEventFilter(engine.vptr) + proc newQGuiApplication*(): QGuiApplication = - ## Return a new QApplication + ## Return a new QGuiApplication new(result, delete) result.setup() From 9b0a477b3b63f0dd7b26ef78c505da4e4d23c4ea Mon Sep 17 00:00:00 2001 From: Andrei Smirnov Date: Tue, 20 Jul 2021 07:11:07 +0300 Subject: [PATCH 2/2] Removed cmdline args passing to Qt --- src/nimqml/private/dotherside.nim | 4 ++-- src/nimqml/private/qapplication.nim | 8 ++++---- src/nimqml/private/qguiapplication.nim | 8 +------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/nimqml/private/dotherside.nim b/src/nimqml/private/dotherside.nim index 8f65a0e..59ea3bb 100644 --- a/src/nimqml/private/dotherside.nim +++ b/src/nimqml/private/dotherside.nim @@ -129,7 +129,7 @@ proc dos_qapplication_enable_hdpi() {.cdecl, dynlib: dynLibName, importc.} proc dos_qapplication_initialize_opengl() {.cdecl, dynlib: dynLibName, importc.} # QApplication -proc dos_qapplication_create(appName: cstring) {.cdecl, dynlib: dynLibName, importc.} +proc dos_qapplication_create() {.cdecl, dynlib: dynLibName, importc.} proc dos_qapplication_exec() {.cdecl, dynlib: dynLibName, importc.} proc dos_qapplication_quit() {.cdecl, dynlib: dynLibName, importc.} proc dos_qapplication_icon(filename: cstring) {.cdecl, dynlib: dynLibName, importc.} @@ -138,7 +138,7 @@ proc dos_qapplication_clipboard_setText(content: cstring) {.cdecl, dynlib: dynLi proc dos_qapplication_installEventFilter(engine: DosQQmlApplicationEngine) {.cdecl, dynlib: dynLibName, importc.} # QGuiApplication -proc dos_qguiapplication_create(argc: cint, argv: cstringArray) {.cdecl, dynlib: dynLibName, importc.} +proc dos_qguiapplication_create() {.cdecl, dynlib: dynLibName, importc.} proc dos_qguiapplication_exec() {.cdecl, dynlib: dynLibName, importc.} proc dos_qguiapplication_quit() {.cdecl, dynlib: dynLibName, importc.} proc dos_qguiapplication_icon(filename: cstring) {.cdecl, dynlib: dynLibName, importc.} diff --git a/src/nimqml/private/qapplication.nim b/src/nimqml/private/qapplication.nim index 10a1163..59cc74f 100644 --- a/src/nimqml/private/qapplication.nim +++ b/src/nimqml/private/qapplication.nim @@ -1,6 +1,6 @@ -proc setup*(application: QApplication, appName: string) = +proc setup*(application: QApplication) = ## Setup a new QApplication - dos_qapplication_create(appName.cstring) + dos_qapplication_create() application.deleted = false proc exec*(application: QApplication) = @@ -28,7 +28,7 @@ proc delete*(application: QApplication) = dos_qapplication_delete() application.deleted = true -proc newQApplication*(appName: string = "Unknown"): QApplication = +proc newQApplication*(): QApplication = ## Return a new QApplication new(result, delete) - result.setup(appName) + result.setup() diff --git a/src/nimqml/private/qguiapplication.nim b/src/nimqml/private/qguiapplication.nim index 39435b3..53c3aa3 100644 --- a/src/nimqml/private/qguiapplication.nim +++ b/src/nimqml/private/qguiapplication.nim @@ -2,13 +2,7 @@ import os proc setup*(self: QGuiApplication) = ## Setup a new QGuiApplication - var argv = allocCStringArray([]) - argv[0] = getAppFilename().cstring - for argi in 1..paramCount(): - argv[argi] = paramStr(argi).cstring - - var argc = paramCount() + 1 - dos_qguiapplication_create(argc.cint, argv) + dos_qguiapplication_create() self.deleted = false proc delete*(self: QGuiApplication) =