[Qt-jambi-interest] Emitter example required

Eskil Abrahamsen Blomfeldt eblomfel at trolltech.com
Wed May 14 16:18:12 CEST 2008


Derek Fountain wrote:
> Can someone either point me at, or show me the guts of, an example of using an emitter?
>   

Sure, several of our examples use signals.

Tetrix is one example that declares its own signals:

    
http://doc.trolltech.com/qtjambi-4.4.0_01/doc/html/com/trolltech/qt/qtjambi-tetrix.html

> Specifically I'd like to emit a signal called "colorChanged" which carries a String containing the name of the colour something has changed to. My best effort to date is:
>
>     QSignalEmitter.Signal1<String> e = new QSignalEmitter.Signal1<String>();
>     e.emit("blue");
>
> which at least compiled. :) But a) it doesn't carry the name of a signal (where do I specify the "colorChanged" name?) and b) it caused a runtime exception.
>   

The name of the signal is the name of the object. In this case, you have 
named your signal 'e'. If you want to make a signal called colorChanged, 
do the following:

    Signal1<String> colorChanged = new Signal1<String>();

Signals must be declared as members of your class. I'm guessing this is 
the reason for your run time exception (was the message of the run time 
exception "Signals must be declared as members of QSignalEmitter 
subclasses", if so then this is your problem.)

The documentation for using signals and slots is available at the 
following address:

    
http://doc.trolltech.com/qtjambi-4.4.0_01/doc/html/com/trolltech/qt/qtjambi-signalsandslots.html


-- Eskil


More information about the Qt-jambi-interest mailing list