D2 GUI Libs

Nick Sabalausky a at a.a
Sun Dec 13 09:43:59 PST 2009


"Nick Sabalausky" <a at a.a> wrote in message 
news:hg394f$mr1$1 at digitalmars.com...
> "Eldar Insafutdinov" <e.insafutdinov at gmail.com> wrote in message 
> news:hg2p87$2ttj$1 at digitalmars.com...
>>
>> 1) You may know the concept of signals and slots in Qt. Consider the 
>> following snippet:
>>
>> class Test : QObject
>> {
>>    mixin Signal!("signal_1(string)");
>>
>>    mixin Slot!("slot_1(string str)");
>>    void slot_1(string str)
>>    {
>>        writefln("slot_1 invoked with ~ " str);
>>    }
>>
>>    mixin Q_OBJECT;
>> }
>>
>> In Qt objects, that inherit from QObject are capable of having signals 
>> and slots and participate in connections. In the current scheme mixins of 
>> Signal and Slot template mix some static information into the class. The 
>> class is then scanned when Q_OBJECT template is mixed in and the proper 
>> meta-information is generated to register signals and slots in the Qt 
>> type system.
>> As you see, this declaration is a bit ugly. In particular defining a slot 
>> requires to duplicate its signature in a mixin. What would really be 
>> awesome is a mechanism allowing something like:
>>
>>    @Slot
>>    void slot_1(string str)
>>    {
>>        writefln("slot_1 invoked with " ~ str);
>>    }
>> I.e we need annotations. But I am not sure how this will work. One of the 
>> possible solutions will be that @Slot expands into mixin Slot!(symbol, 
>> AnnotationArg1, ...).
>>
>

Oops, slight typo:

> Try string mixins, something like this:
>
> 1. Rename Slot to _Slot.
>
> 2. Do this:
>

// Fixed:
template Slot(string decl, string body)
{
    const string Slot = "
        mixin _Slot!("~decl.stringof~");
        void slot_1(string str)
        {
            "~body.stringof~"
        }
    ";
}

>
> class Test : QObject
> {
>    mixin Signal!("signal_1(string)");
>
>    mixin( Slot!("slot_1(string str)", q{
>        writefln("slot_1 invoked with ~ " str);
>    }) );
>
>   mixin Q_OBJECT;
> }
>
> 





More information about the Digitalmars-d mailing list