QObject Class Reference


The QObject class is the base class of all Qt objects that can deal with signals, slots and events. (details) (complete member list)

#include <qobject.h>

Inherited by QAccel, QSenderObject, QSignal, QTimer and QWidget.

Public Members

Static Public Members

Protected Members


Detailed Description

The QObject class is the base class of all Qt objects that can deal with signals, slots and events.

Qt uses a very powerful mechanism, signals that are connected to slots, for communication between objects. An object has zero or more signals and zero or more slots, and a signal may be connected to a slot in any object.

When an object has changed in some way that might be interesting, it emits a signal to tell whoever is interested. If that signal is connected to any slots, those slots get called.

That is. the calling or emitting object doesn't need to know or care what slot the signal is connected to. It works much like the traditional callback mechanism, but it isn't necessary to write null pointer checks or for loops all the time.

QScrollBar is a good example. In order to use it, you create a scroll bar, connect its newValue() signal to a slot which e.g. scrolls your widget. Then, if it suits you, you can connect e.g. QScrollBar::nextLine() to a suitable slot. nextLine() is useless in most cases but if you need it, it's there.


Member Function Documentation

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

Constructs an object with parent objects parent and a name.

The parent of a widget may be viewed as the object's owner. For instance, a dialog box is the parent of the "ok" and "cancel" buttons inside it.

An object destroys its child objects when it is destroyed itself.

Sending a null pointer as parent makes an object with no parent. If the object is a widget, it will become a top-level window.

The name is not used at present.

See also: destroy(), destroyed(), name(), QWidget.

QObject::~QObject ()

Destroys the object and all its children objects.

All signals to and from the object are automatically disconnected.

const QObjectList * QObject::children () const

Returns a pointer to a list of this object's children. High priority children are first on the list.

This function is not for the inexperienced.

See also: insertChild(), removeChild(), parent().

const char * QObject::className () const

Returns this object's type as an ASCII string. This is the actual type, not what the object is used as:

  QRadioButton * rb = new QRadioButton( parent, "example" );
  Button * b;

  b = rb;
  ASSERT ( strcmp( b->name(), "example" ) == 0 )
  ASSERT ( strcmp( b->className(), "QRadioButton" ) == 0 )

This happens through the magic of the moc.

See also: name().

bool QObject::connect (QObject *sender, const char *signal, const char *member) const

Connects signal from object sender to member in this object.

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

Disconnects signal from member of receiver.

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

Disconnects all signals in this object from member of receiver.

To do:

bool QObject::disconnect (QObject *sender, const char *signal, const QObject *receiver, const char *member)

Disconnects signal in object sender from member in object receiver.

If signal is null, disconnect() breaks any connections that pass the other tests.

If member is null, disconnect() breaks any connections that pass the other tests.

If receiver is null, disconnect() breaks any connections that pass the other tests.

See also: connect().

bool QObject::highPriority () const

Returns TRUE if the object is high priority. High priority objects are placed first in an object's list of children, on the assumption that they'll be referenced very often.

Currently only QAccel is high priority.

bool QObject::inherits (const char *clname) const

Returns TRUE if this object is an istance of a class that inherits clname. (A class is considered to inherit itself.)

  QTimer *t = new QTimer;       // QTimer inherits QObject
  t->inherits("QTimer");        // returns TRUE
  t->inherits("QObject");       // returns TRUE
  t->inherits("QButton");       // returns FALSE

This function may be used to determine whether a given object supports certain features. Qt uses it to implement keyboard accelerators, for instance: A keyboard accelerator is an object for which inherits("QAccel") is TRUE.

See also: isA().

void QObject::installEventFilter (const QObject *obj)

Adds an event filter to the list.

See also: removeEventFilter(), eventFilter(), event().

bool QObject::isWidgetType () const

Returns TRUE if the object is a widget, FALSE if not.

QMetaObject * QObject::metaObject () const

Returns a pointer to this object's meta object. The meta object is generated by the meta object compiler, and is used for e.g. signals, slots, inherits(), isA().

const char * QObject::name () const

Returns the name of this object.

See also: setName().

QObject * QObject::parent () const

Returns a pointer to this object's parent.

This function is not for the inexperienced.

See also: children().

void QObject::removeEventFilter (const QObject *obj)

Removes an event filter from the list.

See also: installEventFilter(), eventFilter(), event().

QObject * QObject::sender ()

This functions has not yet been documented; see our home page for updates.

bool QObject::signalsBlocked () const

Returns TRUE if this object is currently not accepting signals.

See also: blockSignals().


This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 04:27, 1995/05/20 by the webmaster at Troll Tech