Why is it hard to make Qt bindings?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Jul 5 14:31:08 UTC 2018


On Thursday, July 05, 2018 11:42:39 drug via Digitalmars-d-learn wrote:
> There were several attempts to make Qt binding for dlang, but either
> they has failed or has been stalled. It would be nice to collect that
> experience. Considering 2.081 supports C++ special member (not all but
> majority) isn't it time to make another attempt or the problem is more
> complex?
> Could you publish your experience in making Qt bindings here?

Qt takes advantage of just about every advanced C++98 feature under the sun,
and on top of that, it uses its own preprocessor for stuff like signals and
slots so that you can do

signal:

and

slot:

in your code and have the functions that follow treated as signals and
slots, and various bits of code get generated to go with all of that. It
also does some very specific stuff with how it handles memory which can be a
bit entertaining to make work well with D code. And of course, Qt makes
heavy use of multiple inheritance, and while that can be dealt with on some
level with interfaces, all of the various issues combined make it
particularly difficult if you want to be able to do the equivalent of
new MyQWidget and have it work properly. There are ways to work around most
of it in D, but it's hard - especially if you don't want to be generating
C++ code as part of your D project that uses Qt. Binding to C++ is far
harder than C, and with Qt being as complicated as it is with what it's
done, it makes it very hard to make D bindings for - not impossible, but
very hard. If someone were _trying_ to make a C++ project that was hard to
bind to, they could probably make it much worse (e.g. much heavier use of
templates), but Qt did a pretty amazing job of making it hard even without
that being their goal.

I actually started on creating bindings (more wrappers for it really) a
while back, but I have a long way to go on it and have gotten sidetracked -
e.g. one of the main reasons that I wrote dxml was because I'm using XML
files to configure code generation for the bindings, and I didn't want to
continue to use std.experimental.xml for that (not only is it unsupported,
but I had to work around various issues while using it, so it clearly was
unacceptable long term).

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list