Dissecting the SS
Bradley Smith
user at domain.invalid
Thu Sep 28 17:27:12 PDT 2006
J Duncan wrote:
> // what QT-style SS would look like in D
>
> class AClass
> {
> void aSignal(int i);
> }
>
> class BClass
> {
> void aSlot(int i) { writefln("signal triggered %s", i); }
> }
>
> void main()
> {
> AClass a = new AClass;
>
> BClass b = new BClass;
>
> connect( a, "aSignal(int)", b, "aSlot(int)" );
>
> a.aSignal(10); // -> writes "signal triggered 10"
> }
>
>
> i just wanted to give an example of how qt does it. the qt moc generates
> the code for the function 'aSignal', this gives it a feeling like its
> part of the language. the moc also generates code to map signal and slot
> names to addresses. they also provide basic named properties (named data
> members with set/get methods) this way. this results in a pretty nice
> system that allows things like automatic signal slot connections in gui
> classes based on names, (ex. the 'edit1' widget automatically sends a
> 'textChanged' signal to a slot on a parent widget called
> 'edit1_textChanged') i dont really have a point to make, i just wanted
> to give a simple example of qt.
>
Is there something more to the QT mechanism? I'm not a QT user, but I
figure there must be more too it. Otherwise, why not use the following?
import std.stdio;
class AClass
{
// void aSignal(int i);
void delegate(int) aSignal;
}
class BClass
{
void aSlot(int i) { writefln("signal triggered %s", i); }
}
void main()
{
AClass a = new AClass;
BClass b = new BClass;
//connect( a, "aSignal(int)", b, "aSlot(int)" );
a.aSignal = &b.aSlot;
a.aSignal(10); // -> writes "signal triggered 10"
}
Bradley
More information about the Digitalmars-d
mailing list