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.
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-gen
is part of the seaqt
family of projects each targeting a different aspect of Qt binding development:
seaqt-gen
usesclang
to parse Qt C++ headers and outputs a correspondingC
interface - if you have your ownC++
-based components that you wish to expose toC
, 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
containsQt
binding code forC
generated byseaqt-gen
- this is the main repository to use if you want to consume the bindings in your application or languagenim-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!
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 spawnedDOtherSide
-C
bindings focusing on the QML subset of Qt - similarly aims to be a base for multiple languagesQtJambi
-java
bindings that similar tomiqt
uses a generator approach for broad Qt coverage along with garbage-collection supportcxx-qt
- more on lifetime design and metaobject integration
Same as miqt
, the bindings are MIT-licensed but you have to take care to follow Qt's licensing as well.
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.
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 similargo
-specific constructs have been removed along with the generatedgo
code itself - while the binding generator itself remains written ingo
, the generated code has no dependencies beyondQt
itself (andpkg-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.
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).