Q3Signal Class Reference

#include <q3signal.h>

Inheritance diagram for Q3Signal:

Inheritance graph
[legend]
Collaboration diagram for Q3Signal:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Q3Signal class can be used to send signals for classes that don't inherit QObject.

If you want to send signals from a class that does not inherit QObject, you can create an internal Q3Signal object to emit the signal. You must also provide a function that connects the signal to an outside object slot. This is how we used to implement signals in Qt 3's QMenuData class, which was not a QObject. In Qt 4, menus contain actions, which are QObjects.

In general, we recommend inheriting QObject instead. QObject provides much more functionality.

You can set a single QVariant parameter for the signal with setValue().

Note that QObject is a private base class of Q3Signal, i.e. you cannot call any QObject member functions from a Q3Signal object.

Example:

  #include <q3signal.h>

  class MyClass
  {
  public:
      MyClass();
      ~MyClass();

      void doSomething();

      void connect(QObject *receiver, const char *member);

  private:
      Q3Signal *sig;
  };

  MyClass::MyClass()
  {
      sig = new Q3Signal;
  }

  MyClass::~MyClass()
  {
      delete sig;
  }

  void MyClass::doSomething()
  {
      // ... does something
      sig->activate(); // emits the signal
  }

  void MyClass::connect(QObject *receiver, const char *member)
  {
      sig->connect(receiver, member);
  }

Definition at line 34 of file q3signal.h.

Signals

void signal (const QVariant &)
void intSignal (int)

Public Member Functions

 Q3Signal (QObject *parent=0, const char *name=0)
 ~Q3Signal ()
bool connect (const QObject *receiver, const char *member)
bool disconnect (const QObject *receiver, const char *member=0)
void activate ()
bool isBlocked () const
void block (bool b)
void setParameter (int value)
int parameter () const
void setValue (const QVariant &value)
QVariant value () const

Private Attributes

QVariant val


Constructor & Destructor Documentation

Q3Signal::Q3Signal ( QObject parent = 0,
const char *  name = 0 
)

Constructs a signal object called name, with the parent object parent. These arguments are passed directly to QObject.

Definition at line 98 of file q3signal.cpp.

References val.

00099     : QObject(parent, name)
00100 {
00101 #ifndef QT_NO_VARIANT
00102     val = 0;
00103 #endif
00104 }

Q3Signal::~Q3Signal (  ) 

Destroys the signal. All connections are removed, as is the case with all QObjects.

Definition at line 110 of file q3signal.cpp.

00111 {
00112 }


Member Function Documentation

bool Q3Signal::connect ( const QObject receiver,
const char *  member 
)

Connects the signal to member in object receiver.

See also:
disconnect(), QObject::connect()

Definition at line 128 of file q3signal.cpp.

References QObject::connect(), intSignal(), intSignature(), SIGNAL, and signal().

Referenced by Q3Accel::connectItem().

00129 {
00130 #ifndef QT_NO_VARIANT
00131     if (intSignature(member))
00132 #endif
00133   return QObject::connect((QObject *)this, SIGNAL(intSignal(int)), receiver, member);
00134 #ifndef QT_NO_VARIANT
00135     return QObject::connect((QObject *)this, SIGNAL(signal(QVariant)),
00136            receiver, member);
00137 #endif
00138 }

Here is the call graph for this function:

bool Q3Signal::disconnect ( const QObject receiver,
const char *  member = 0 
)

Disonnects the signal from member in object receiver.

See also:
connect(), QObject::disconnect()

Reimplemented from QObject.

Definition at line 146 of file q3signal.cpp.

References QObject::disconnect(), intSignal(), intSignature(), SIGNAL, and signal().

Referenced by Q3Accel::disconnectItem().

00147 {
00148     if (!member)
00149   return QObject::disconnect((QObject *)this, 0, receiver, member);
00150 #ifndef QT_NO_VARIANT
00151     if (intSignature(member))
00152 #endif
00153   return QObject::disconnect((QObject *)this, SIGNAL(intSignal(int)), receiver, member);
00154 #ifndef QT_NO_VARIANT
00155     return QObject::disconnect((QObject *)this, SIGNAL(signal(QVariant)),
00156         receiver, member);
00157 #endif
00158 }

Here is the call graph for this function:

void Q3Signal::activate (  ) 

Emits the signal. If the platform supports QVariant and a parameter has been set with setValue(), this value is passed in the signal.

Definition at line 189 of file q3signal.cpp.

References emit, intSignal(), signal(), QVariant::toInt(), and val.

Referenced by Q3AccelPrivate::activate(), and Q3AccelPrivate::activateAmbiguously().

00190 {
00191 #ifndef QT_NO_VARIANT
00192     /* Create this Q3GuardedPtr on this, if we get destroyed after the intSignal (but before the variant signal)
00193        we cannot just emit the signal (because val has been destroyed already) */
00194     QPointer<Q3Signal> me = this;
00195     if(me)
00196   emit intSignal(val.toInt());
00197     if(me)
00198   emit signal(val);
00199 #else
00200     emit intSignal(0);
00201 #endif
00202 }

Here is the call graph for this function:

bool Q3Signal::isBlocked (  )  const [inline]

Returns true if the signal is blocked, or false if it is not blocked.

The signal is not blocked by default.

See also:
block(), QObject::signalsBlocked()

Definition at line 47 of file q3signal.h.

References QObject::signalsBlocked().

00047 { return QObject::signalsBlocked(); }

Here is the call graph for this function:

void Q3Signal::block ( bool  b  )  [inline]

Blocks the signal if b is true, or unblocks the signal if b is false.

An activated signal disappears into hyperspace if it is blocked.

See also:
isBlocked(), activate(), QObject::blockSignals()

Definition at line 48 of file q3signal.h.

References QObject::blockSignals().

Here is the call graph for this function:

void Q3Signal::setParameter ( int  value  ) 

Definition at line 228 of file q3signal.cpp.

References val.

00229 {
00230     val = value;
00231 }

int Q3Signal::parameter (  )  const

Definition at line 234 of file q3signal.cpp.

References QVariant::toInt(), and val.

00235 {
00236     return val.toInt();
00237 }

Here is the call graph for this function:

void Q3Signal::setValue ( const QVariant value  ) 

Sets the signal's parameter to value

Definition at line 208 of file q3signal.cpp.

References val, and value().

00209 {
00210     val = value;
00211 }

Here is the call graph for this function:

QVariant Q3Signal::value (  )  const

Returns the signal's parameter

Definition at line 216 of file q3signal.cpp.

References val.

Referenced by setValue().

00217 {
00218     return val;
00219 }

void Q3Signal::signal ( const QVariant  )  [signal]

Referenced by activate(), connect(), and disconnect().

void Q3Signal::intSignal ( int   )  [signal]

Referenced by activate(), connect(), and disconnect().


Member Data Documentation

QVariant Q3Signal::val [private]

Definition at line 68 of file q3signal.h.

Referenced by activate(), parameter(), Q3Signal(), setParameter(), setValue(), and value().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:16:46 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1