Nick Sabalausky Wrote: > "Nick Sabalausky" <[email protected]> wrote in message > news:[email protected]... > > "Eldar Insafutdinov" <[email protected]> wrote in message > > news:[email protected]... > >> > >> 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; > > } > > > > > >
Thank you for suggestion, but while reducing redundancy it became even uglier! I'll better stay with the current syntax.
