DQt: Qt bindings using extern(C++)

Tim tim.dlang at t-online.de
Tue Dec 7 16:35:28 UTC 2021


On Tuesday, 7 December 2021 at 06:33:18 UTC, MGW wrote:
> Can you explain in more detail some points that are difficult 
> for me:
>
> widgets/label.d file. I see a C++ mapping of class 
> QLabelPrivate to structure D
> extern(C++, class) struct QLabelPrivate;
> this makes sense.
>
> I see below an implementation of a class D named QLabel
> class /+ Q_WIDGETS_EXPORT +/ QLabel : QFrame
> in which I see calls to methods of the QLabel class.
>
> I don't understand at what stage (where exactly) the mapping
> QLabelPrivate structure methods onto QLabel methods.
>
> I expected to see something like:
> QLabelPrivate dd = QLabelPrivate(...);
> and then
> dd.MetodsQLabel(...)
>
> Can you explain this place in more detail.

QLabel is also extern(C++), because the top of the file has 
"extern(C++):". Most methods in QLabel are directly implemented 
in the Qt library. Some are also implemented in D. For example 
QLabel.setText has a wrapper accepting the text without ref, so 
it can be called without creating a temporary variable.

QLabelPrivate is used internally by Qt. This declaration is 
actually unused in the bindings. Many Qt types have a pointer to 
private data. New versions of Qt can then change the private data 
without changing the ABI between Qt libraries and applications. 
The constructor of QLabel creates an instance of QLabelPrivate 
and passes it to the constructor of the parent class 
(https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlabel.cpp.html#213). QObject stores it then as d_ptr.


More information about the Digitalmars-d-announce mailing list