Hi,

it took me some time, but I have generated bindings for the Qt framework. The 
main goal with these bindings is supporting the creation of GUIs, not exposing 
the complete, massive Qt framework. Currently Qt 6.4.1 is targeted, but I guess 
Qt 6.*.* (and Qt5 and Qt4, if some compiler flags are changed) should also 
work, as the API is stable enough.

In addition to the bindings, I also created some macros to make using it in nim 
as painless as possible :) One macro (`inheritQObject`) allows for easy 
creation of new objects that inherit from a QObject (or descendant), together 
with overriding methods and defining new slots for the object. Another macro 
allows for easily generating layouts, using a `QGridLayout`, `QVBoxLayout`, 
`QHBoxLayout` and `QSplitter`, and conveniently setting properties and 
connecting signals with slots.

# Installation

`nimble install https://github.com/jerous86/nimqt`

I will add it later to the nimble.directory, but for now I just want some 
feedback from here :)

# Example
    
    
    import nimqt
    import nimqt/[qpushbutton, qboxlayout]
    
    nimqt.init
    let app = newQApplication()
    
    inheritQObject(GuiHandler, QObject):
        slot_decl on_helloWorld_clicked()
    
    let guiHandler: ptr GuiHandler = newGuiHandler()
    let win: ptr QWidget = newQWidget()
    
    win.makeLayout:
        - newQPushButton(Q "Click me!!"):
            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()
    
    
    Run

will generate something like

when run with `nim cpp -r examples/hello.nim`.

# Documentation

The `README.md` on <https://github.com/jerous86/nimqt> contains information on 
how to use the library. In the `examples` directory in the repository there are 
a couple of examples.

For the availability of modules, just look in the `qt/6.4.1_minimal/nimqt` 
directory in the repository.

For documentation on the Qt modules, see the Qt documentation at 
<https://doc.qt.io/qt-6/>.

Note that not all methods are supported due to some issues with recursive 
module imports, but in general, I think the most useful methods are available. 
The modules are mainly those that support creating GUIs (i.e. QtGui and 
QtWidgets components), and skipping many of the `QAbstract*` classes.

There are scripts, using libclang, to generate bindings for other classes (i.e. 
QRegularExpression etc), but these are not added as I don't think they add much 
value. The set of classes for which there are bindings might change over time.

Reply via email to