C++ Binding Generator

w0rp devw0rp at gmail.com
Sun Feb 16 16:36:57 PST 2014


On Saturday, 15 February 2014 at 03:36:29 UTC, michaelc37 wrote:
>
>> [1]
>> QtD is not actively maintained.  It existed on
>> BitBucket: https://bitbucket.org/qtd/repo
>> before someone else forked it and moved to
>> GitHub: https://github.com/qtd-developers/qtd
>
> Probably worth mentioning.
> There are also some recent startup efforts to generate qt 
> bindings based on smoke qt.
>
> https://github.com/w0rp/dqt
> https://github.com/GlobecSys/smoke.d
>
> However, its qt4.

I'm working on this slowly. I'll post more when I actually have 
something worth looking at.

My library takes the SMOKE data generated by smokeqt and then 
does at least 90% of the work in D code to manipulate it, for 
generating D source files and loading C++ function pointers at 
runtime so you can wrap C++ classes in D classes. If you have the 
SMOKE data already in a shared library already I recommend this, 
as you can get much better results this way. There is some 
additional C++ code for two reasons. First, because smokeqt 
doesn't generate bindings for QString, which is weird and 
annoying, so I have to provide functions with C calling 
conventions written in C++ for creating QStrings. The second 
reason is that the functions for creating and deleting the QtGUI 
and QtCore SMOKE structs just don't seem to work when you call 
them directly from D, but do work when I wrap them again in 
functions with C calling conventions.

Right now I have a generator which spits out a full list of 
methods and classes, also enums with the right values at the 
moment, and I need to do more work to get it to map from C++ type 
to D type, generate required import lines for tying things 
together, and then generate the snippets of code in methods to 
tie to the code I wrote before for loading the function pointers 
on startup. After that it should work, but not well enough to be 
that useful.

I'll try Qt5 later. The main reason I'm trying to get Qt4 working 
at the moment is that I have experience with Qt4, but not with 
Qt5, and from my understanding a lot of the advantages of Qt5 
come from QML, and I don't quite understand yet how QML would tie 
together with a D API.

If I manage to get my bindings to work, I could see how you could 
take that and move on to creating a generalised C++ binding 
generator, but what you get would never be that great. It would 
be much better to have some kind of support in the language or 
runtime for doing the remaining things D can't do at the moment, 
like matching C++ function calling conventions, calling virtual 
methods, I don't know how you'd get multiple inheritance or 
stack-based classes to work. I get why all of this stuff just 
doesn't exist already, because it's really hard to implement and 
requires a lot of careful thought about it.


More information about the Digitalmars-d mailing list