Dissecting the SS
Lutger
lutger.blijdestijn at gmail.com
Thu Sep 28 18:00:53 PDT 2006
Bradley Smith wrote:
>
> 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?
>
Yes, J Duncan posted is how it could look like in D. In QT you must
declare signal and slots capable classes with a macro, then QT uses a
custom preprocessor to do all the magic, here is an example from the docs:
class Foo : public QObject
{
Q_OBJECT
public:
Foo();
int value() const { return val; }
public slots:
void setValue( int );
signals:
void valueChanged( int );
private:
int val;
};
void Foo::setValue( int v )
{
if ( v != val ) {
val = v;
emit valueChanged(v);
}
}
Foo a, b;
connect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int)));
b.setValue( 11 ); // a == undefined b == 11
setValue( 79 ); // a == 79 b == 79
b.value(); // returns 79
http://doc.trolltech.com/3.3/signalsandslots.html
More information about the Digitalmars-d
mailing list