Qt bindings for D

Abdulhaq alynch4047 at gmail.com
Mon Oct 14 12:11:37 PDT 2013


On Monday, 14 October 2013 at 18:27:52 UTC, Kagamin wrote:
> On Sunday, 13 October 2013 at 12:39:55 UTC, Abdulhaq wrote:
>> Anyway I treated it as an educational exercise and make QRect 
>> et al. regular classes, and got it generally working again.
>
> QRect as a class doesn't sound good: the class layouts are 
> incompatible between D and C++. If you want to mimic C++ data 
> layout, you should do it manually - use structs with pads or 
> translate the data at the border of languages.

In the binding my making QRect/QLine/QPoint bound as a class 
means that data access is through methods and so always works 
regardless of the way the compiler lays out the data - whereas it 
was previously being treated as a struct, which didn't work on my 
64bit machine. I want to keep the wrapper as simple as possible 
(personally) so avoid padding data etc. I also wanted something 
quick to do as I had no idea how much other work would be 
required before anything worked at all.

I'm not a C++ developer (I read it a fair amount but write very 
little) but my understanding of what was happening is that in the 
developers' environment the C++ and D compilers laid out the 
class the same, wheres on 64bit Linux I found that (after a lot 
of time debugging) that while things compiled, they didn't work 
due to corruption in QRect when passing through the wrapper.

I guess the original developers made QRect/QLine/QPoint structs 
for performance reasons, but in my own Qt experience you don't 
actually deal with that many instances of these types so 
application performance is not sensitive to how they are wrapped 
(of course YMMV).

Ultimately, it didn't work for me before whereas it does now :-)


More information about the Digitalmars-d mailing list