Can D be cute? (Qt)
Justin Johansson
no at spam.com
Sat May 8 05:01:48 PDT 2010
bearophile wrote:
> Justin Johansson:
>> Whilst QtD looks like a cool project, my question was really about
>> whether D could achieve the same sorts of things that Qt does with its
>> meta-object compiler.
>>
>> In other words, and calling a spade a spade, Qt is a "hack" to make C++
>> more pleasant for GUI. Would it be possible for D to achieve natively
>> the same sorts that Qt does via preprocessing to C++.
>
> I suggest you to explain what such things are, and to give some examples too.
>
> Bye,
> bearophile
Okay, perhaps not everybody here is across Qt.
Programming in Qt is almost C++ bu not exactly C++ as Qt uses a
preprocessor to translate "enhanced C++" into "vanilla C++".
Here is an example that demonstrates that "Qt C++" is not "vanilla C++".
In Qt, one adorns class declarations with things that are not valid C++.
So in a class declaration you can say
class MyWidget
{
public:
// regular C++ stuff, attributes and methods
public slots:
// method declarations for intercepting event signals
};
You will observe that "public slots" is not valid C++. Qt's meta-object
compiler does a preprocessing of the MyWidget class so that methods
declared under the "public slots:" scope are subject to some kind of
reflection or introspection that enables events (signals) to be delegate
to the respective methods.
In doing so, according to my naive understanding, the Qt MOC
(meta-object compiler) compiles the MyWidget class retaining knowledge
of compile time analysis of the MyWidget class methods which are
designated as slots.
So this is some kind of black magic that the MOC does to Qt source code
in order to make event routing easier. The concepts of reflection come
to mind here. In a way the MOC processor must be keeping a lot of the
static analysis of classes around in similar fashion that Java does.
Accordingly it is fair to ask why does Qt do this? Obviously Qt
designers do not feel that vanilla C++ is adequate for cutting GUI apps
which is why they resort to a preprocessor.
Now I was thinking about why is C++ deficient for Qt to go to such
resorts. And if vanilla C++ is deficient for GUI programming, and given
that D is viewed by many as a "better C++", then can D do natively what
Qt has to do with a preprocessor?
I'm not an expert on Qt or its MOC (only 2 weeks into it). Perhaps
others on this NG might cotton on to what I'm trying to express and
chime in.
Does the simple example above help explain what I'm on about?
Cheers
Justin Johanssom
More information about the Digitalmars-d
mailing list