jerous86 / nimqt

Qt bindings for nim
GNU General Public License v2.0
101 stars 7 forks source link

Cannot assign to member variables #10

Closed matkuki closed 1 year ago

matkuki commented 1 year ago

Example battle_testing.nim:


import os
import nimqt
import nimqt/[qpushbutton, qboxlayout]

nimqt.init
let app = newQApplication(os.commandLineParams())

inheritQObject(GuiHandler, QObject):
    var a: int

    slot_decl on_helloWorld_clicked()

let guiHandler: ptr GuiHandler = newGuiHandler()
let win: ptr QWidget = newQWidget()
guiHandler.a = 12

let stylesheet: QString = newQString("background: red;")

win.makeLayout:
    - newQPushButton(Q "Click me!!"):
        setStyleSheet(stylesheet)
        connect(SIGNAL "clicked()", guiHandler, SLOT "on_helloWorld_clicked()")
    - newQPushButton( Q "Click me!!"):
        connect(SIGNAL "clicked()", guiHandler, SLOT "on_helloWorld_clicked()")

proc on_helloWorld_clicked(this: ptr GuiHandler) =
    let sender = cast[ ptr QPushButton]( this.get_sender())
    sender.setText( Q "Hello world!")

win.show()
discard app.exec()

... compiles without problems, but running it throws:

$ .\battle_testing.exe
C:\Users\matic\.nimble\pkgs\nimqt-0.1\nimqt.nim(333) battle_testing
C:\Users\matic\.choosenim\toolchains\nim-1.6.10\lib\pure\collections\tables.nim(246) []
C:\Users\matic\.choosenim\toolchains\nim-1.6.10\lib\pure\collections\tables.nim(236) raiseKeyError
Error: unhandled exception: key not found [KeyError]
jerous86 commented 1 year ago

Yes, forgetfulness from my side. Should be fixed now!

matkuki commented 1 year ago

Works now 👍