Can D be cute? (Qt)
Justin Johansson
no at spam.com
Sat May 8 15:53:08 PDT 2010
Marianne Gagnon wrote:
> Hi Justin,
>
> looking at QtD, it seems like it can be done :
>
> In file http://www.dsource.org/projects/qtd/browser/demos/browser/browsermainwindow.d
>
> m_historyHome.triggered().connect(&this.slotHome);
>
> // ...
>
> public:
>
> void slotHome()
> {
> // ...
> }
>
> I however believe that this kind of delegate-connection can also be performed in C++ (with templates?). Maybe Qt developers simply continue using the MOC because they don't want to break backwards compatibility.
>
> -- Auria
Maybe to a small degree but it seems to me that the Qt Meta-Object
Compiler does more than just support signal and slot connections. There
are a number of "C++ extension" that can go in a class declaration like
Q_OBJECT, Q_PROPERTY, Q_ENUMS, Q_CLASSINFO.
e.g. as below from from http://doc.trolltech.com/4.4/moc.html
The MOC mechanism makes it trivial to expose classes in Qt to scripting
with QtScript (basically Qt version of JavaScript).
I haven't dug deep enough into QtD to know how it fares in the scripting
arena though.
Cheers
Justin Johansson
<QtDocumentation>
In addition to the signals and slots shown above, moc also implements
object properties as in the next example. The Q_PROPERTY() macro
declares an object property, while Q_ENUMS() declares a list of
enumeration types within the class to be usable inside the property system.
In the following example, we declare a property of the enumeration type
Priority that is also called priority and has a get function priority()
and a set function setPriority().
class MyClass : public QObject
{
Q_OBJECT
Q_PROPERTY(Priority priority READ priority WRITE setPriority)
Q_ENUMS(Priority)
public:
enum Priority { High, Low, VeryHigh, VeryLow };
MyClass(QObject *parent = 0);
~MyClass();
void setPriority(Priority priority);
Priority priority() const;
};
The Q_FLAGS() macro declares enums that are to be used as flags, i.e.
OR'd together. Another macro, Q_CLASSINFO(), allows you to attach
additional name/value pairs to the class's meta-object:
class MyClass : public QObject
{
Q_OBJECT
Q_CLASSINFO("Author", "Oscar Peterson")
Q_CLASSINFO("Status", "Active")
public:
MyClass(QObject *parent = 0);
~MyClass();
};
</QtDocumentation>
More information about the Digitalmars-d
mailing list