Skip to content

micieslak/seaqt-gen

 
 

Repository files navigation

seaqt-gen

seaqt-gen is a C and Nim binding generator for Qt based on the C part of the miqt bindings for Go.

The bindings are still going through significant changes, including in naming and structure - this repository is a preview intended for feedback.

The code may occasionally be rebased before the dust settles on a generally useful initial release.

Acknowledgements and contributions

seaqt-gen is built on top of the miqt binding generator and wouldn't be possible without it - consider contributing to upstream directly such that the changes may benefit both.

See the relevant upstream issue for more information.

seaqt family

seaqt-gen is part of the seaqt family of projects each targeting a different aspect of Qt binding development:

  • seaqt-gen uses clang to parse Qt C++ headers and outputs a corresponding C interface - if you have your own C++-based components that you wish to expose to C, the generator can similarly be used to wrap that (wip) - you can ignore this repository if all you want to do is use the bindings.
  • seaqt contains Qt binding code for C generated by seaqt-gen - this is the main repository to use if you want to consume the bindings in your application or language
  • nim-seaqt contains binding code for the Nim programming language - similarly, if all you want to do is to use Nim from Qt, you can ignore the other repos

Future repositories may be added to cover additional Qt-based libraries (such as Scintilla) as well as additional tooling. Get in touch to add yours!

Related projects

Qt has been around for a while and as such, there are many binding projects to choose from! seaqt blends ideas from all of them, but in particular:

  • miqt - original set of bindings from which this project spawned
  • DOtherSide - C bindings focusing on the QML subset of Qt - similarly aims to be a base for multiple languages
  • QtJambi - java bindings that similar to miqt uses a generator approach for broad Qt coverage along with garbage-collection support
  • cxx-qt - more on lifetime design and metaobject integration

License

Same as miqt, the bindings are MIT-licensed but you have to take care to follow Qt's licensing as well.

Usage

See miqt documentation for general usage documentation - similar to miqt, bindings are generated by running the generator against a Qt installation.

To keep the generated code stable, bindings get generated inside a Docker container with a fixed Qt version installed.

Upstream changelog

seaqt-gen is currently developed as a set of patches against the upstream miqt repository that - a non-exhaustive list of changes includes:

  • Binding output is directed to a separate repositories/branches to reduce clone size for users
  • Versioning and module organisation more closely follows that of upstream Qt - in particular, modules follow pkg-config/dll boundaries and branches are used to track versions
  • cgo and similar go-specific constructs have been removed along with the generated go code itself - while the binding generator itself remains written in go, the generated code has no dependencies beyond Qt itself (and pkg-config).
  • Non-core components such as Scintilla have been dropped for now - these should eventually reappear should there be interest.
  • Some experimental changes to the generated C/C++ code to make it easier to use "natively" outside of go

As miqt evolves, so will this repository - for now, seaqt-gen gets rebased against upstream regularly - keep this in mind when forking.

C translation details

Inheritance

Inheritance is implemented using a wrapper type (named VirtualXxx for Xxx) which implements each virtual function redirecting the call to a function pointer in a vtable. The vtable is set per instance at construction time.

In addition to the vtable, the caller can request additional memory to be allocated with each instance simulating the typical memory layout of C++ inheritance where storage for the derived members simply extend the memory area reserved for the base type.

The vtable is simply a struct containing a pointer for each virtual function, including the virtual destructor which automatically gets called when the instance is being deleted.

Using QObject as example:

| -----------------------------------------------|
| sizeof(VirtualQObject) + alignment | vdata ... |
|------------------------------------|-----------|
| QObject | const QOjbect_VTable*    | ....      |
|------------------------------------|-----------|

Given a pointer to QObject, the QObject_vdata function returns a pointer to the data section while vdata_QObject performs the reverse similar to how static_cast adjusts pointers to correct for multiple inheritance.

Callers will typically keep a const vtable instance for each derived type they wish to create, using the vdata part for per-instance data (such as when mapping the C++ instance to a host language instance).

About

Binding generator for Qt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 89.8%
  • Dockerfile 5.0%
  • Shell 1.9%
  • C++ 1.9%
  • Makefile 1.2%
  • C 0.2%