QObject is the heart of the TQt object model. The central feature in this model is a very powerful mechanism for seamless object communication called signals and slots. You can connect a signal to a slot with connect() and destroy the connection with disconnect(). To avoid never ending notification loops you can temporarily block signals with blockSignals(). The protected functions connectNotify() and disconnectNotify() make it possible to track connections.
QObjects organize themselves in object trees. When you create a QObject with another object as parent, the object will automatically do an insertChild() on the parent and thus show up in the parent's children() list. The parent takes ownership of the object i.e. it will automatically delete its children in its destructor. You can look for an object by name and optionally type using child() or queryList(), and get the list of tree roots using objectTrees().
.PP
Every object has an object name() and can report its className() and whether it inherits() another class in the QObject inheritance hierarchy.
.PP
When an object is deleted, it emits a destroyed() signal. You can catch this signal to avoid dangling references to QObjects. The QGuardedPtr class provides an elegant way to use this feature.
.PP
QObjects can receive events through event() and filter the events of other objects. See installEventFilter() and eventFilter() for details. A convenience handler, childEvent(), can be reimplemented to catch child events.
.PP
Last but not least, QObject provides the basic timer support in Qt; see QTimer for high-level support for timers.
Notice that the TQ_OBJECT macro is mandatory for any object that implements signals, slots or properties. You also need to run the moc program (Meta Object Compiler) on the source file. We strongly recommend the use of this macro in \fIall\fR subclasses of QObject regardless of whether or not they actually use signals, slots and properties, since failure to do so may lead certain functions to exhibit undefined behaviour.
All TQt widgets inherit QObject. The convenience function isWidgetType() returns whether an object is actually a widget. It is much faster than inherits( "QWidget" ).
Some QObject functions, e.g. children(), objectTrees() and queryList() return a QObjectList. A QObjectList is a QPtrList of QObjects. QObjectLists support the same operations as QPtrLists and have an iterator class, QObjectListIt.
Constructs an object called \fIname\fR with parent object, \fIparent\fR.
.PP
The parent of an object may be viewed as the object's owner. For instance, a dialog box is the parent of the" OK" and "Cancel" buttons it contains.
.PP
The destructor of a parent object destroys all child objects.
.PP
Setting \fIparent\fR to 0 constructs an object with no parent. If the object is a widget, it will become a top-level window.
.PP
The object name is some text that can be used to identify a QObject. It's particularly useful in conjunction with \fIQt Designer\fR. You can find an object by name (and type) using child(). To find several objects use queryList().
.PP
See also parent(), name, child(), and queryList().
.SH "QObject::~QObject ()\fC [virtual]\fR"
Destroys the object, deleting all its child objects.
.PP
All signals to and from the object are automatically disconnected.
.PP
\fBWarning:\fR All child objects are deleted. If any of these objects are on the stack or global, sooner or later your program will crash. We do not recommend holding pointers to child objects from outside the parent. If you still do, the QObject::destroyed() signal gives you an opportunity to detect when an object is destroyed.
.PP
\fBWarning:\fR Deleting a QObject while pending events are waiting to be delivered can cause a crash. You must not delete the QObject directly from a thread that is not the GUI thread. Use the QObject::deleteLater() method instead, which will cause the event loop to delete the object after all pending events have been delivered to the object.
.SH "void QObject::blockSignals ( bool block )"
Blocks signals if \fIblock\fR is TRUE, or unblocks signals if \fIblock\fR is FALSE.
.PP
Emitted signals disappear into hyperspace if signals are blocked. Note that the destroyed() signals will be emitted even if the signals for this object have been blocked.
Returns TRUE if the \fIsignal\fR and the \fImember\fR arguments are compatible; otherwise returns FALSE. (The \fIreceiver\fR argument is currently ignored.)
.PP
\fBWarning:\fR We recommend that you use the default implementation and do not reimplement this function.
Searches the children and optionally grandchildren of this object, and returns a child that is called \fIobjName\fR that inherits \fIinheritsClass\fR. If \fIinheritsClass\fR is 0 (the default), any class matches.
.PP
If \fIrecursiveSearch\fR is TRUE (the default), child() performs a depth-first search of the object's children.
.PP
If there is no such object, this function returns 0. If there are more than one, the first one found is retured; if you need all of them, use queryList().
This event handler can be reimplemented in a subclass to receive child events.
.PP
Child events are sent to objects when children are inserted or removed.
.PP
Note that events with QEvent::type() QEvent::ChildInserted are posted (with QApplication::postEvent()) to make sure that the child's construction is completed before this function is called.
.PP
If a child is removed immediately after it is inserted, the \fCChildInserted\fR event may be suppressed, but the \fCChildRemoved\fR event will always be sent. In such cases it is possible that there will be a \fCChildRemoved\fR event without a corresponding \fCChildInserted\fR event.
.PP
If you change state based on \fCChildInserted\fR events, call QWidget::constPolish(), or do
The first child added is the first object in the list and the last child added is the last object in the list, i.e. new children are appended at the end.
.PP
Note that the list order changes when QWidget children are raised or lowered. A widget that is raised becomes the last object in the list, and a widget that is lowered becomes the first object in the list.
.PP
See also child(), queryList(), parent(), insertChild(), and removeChild().
Connects \fIsignal\fR from the \fIsender\fR object to \fImember\fR in object \fIreceiver\fR, and returns TRUE if the connection succeeds; otherwise returns FALSE.
.PP
You must use the SIGNAL() and SLOT() macros when specifying the \fIsignal\fR and the \fImember\fR, for example:
This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return FALSE: QObject::connect( scroll, SIGNAL(valueChanged(int v)), label, SLOT(setNum(int v)) );
In this example, the MyWidget constructor relays a signal from a private member variable, and makes it available under a name that relates to MyWidget.
.PP
A signal can be connected to many slots and signals. Many signals can be connected to one slot.
.PP
If a signal is connected to several slots, the slots are activated in an arbitrary order when the signal is emitted.
.PP
The function returns TRUE if it successfully connects the signal to the slot. It will return FALSE if it cannot create the connection, for example, if QObject is unable to verify the existence of either \fIsignal\fR or \fImember\fR, or if their signatures aren't compatible.
.PP
A signal is emitted for \fIevery\fR connection you make, so if you duplicate a connection, two signals will be emitted. You can always break a connection using disconnect().
.PP
See also disconnect().
.PP
Examples:
.)l action/main.cpp, application/main.cpp, extension/main.cpp, iconview/main.cpp, network/archivesearch/main.cpp, regexptester/main.cpp, and t2/main.cpp.
This virtual function is called when something has been connected to \fIsignal\fR in this object.
.PP
\fBWarning:\fR This function violates the object-oriented principle of modularity. However, it might be useful when you need to perform expensive initialization only if something is connected to a signal.
This event handler can be reimplemented in a subclass to receive custom events. Custom events are user-defined events with a type value at least as large as the "User" item of the QEvent::Type enum, and is typically a QCustomEvent or QCustomEvent subclass.
This signal is emitted when the object is being destroyed.
.PP
Note that the signal is emitted by the QObject destructor, so the object's virtual table is already degenerated at this point, and it is not safe to call any functions on the object emitting the signal. This signal can not be blocked.
.PP
All the objects's children are destroyed immediately after this signal is emitted.
Disconnects \fIsignal\fR in object \fIsender\fR from \fImember\fR in object \fIreceiver\fR.
.PP
A signal-slot connection is removed when either of the objects involved are destroyed.
.PP
disconnect() is typically used in three ways, as the following examples demonstrate. <ol type=1>
.IP 1
Disconnect everything connected to an object's signals:
.IP
.nf
.br
disconnect( myObject, 0, 0, 0 );
.br
.fi
equivalent to the non-static overloaded function
.IP
.nf
.br
myObject->disconnect();
.br
.fi
.IP 2
Disconnect everything connected to a specific signal:
.IP
.nf
.br
disconnect( myObject, SIGNAL(mySignal()), 0, 0 );
.br
.fi
equivalent to the non-static overloaded function
.IP
.nf
.br
myObject->disconnect( SIGNAL(mySignal()) );
.br
.fi
.IP 3
Disconnect a specific receiver:
.IP
.nf
.br
disconnect( myObject, 0, myReceiver, 0 );
.br
.fi
equivalent to the non-static overloaded function
.IP
.nf
.br
myObject->disconnect( myReceiver );
.br
.fi
.PP
0 may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively.
.PP
The \fIsender\fR may never be 0. (You cannot disconnect signals from more than one object in a single call.)
.PP
If \fIsignal\fR is 0, it disconnects \fIreceiver\fR and \fImember\fR from any signal. If not, only the specified signal is disconnected.
.PP
If \fIreceiver\fR is 0, it disconnects anything connected to \fIsignal\fR. If not, slots in objects other than \fIreceiver\fR are not disconnected.
.PP
If \fImember\fR is 0, it disconnects anything that is connected to \fIreceiver\fR. If not, only slots named \fImember\fR will be disconnected, and all other slots are left alone. The \fImember\fR must be 0 if \fIreceiver\fR is left out, so you cannot disconnect a specifically-named slot on all objects.
This virtual function is called when something has been disconnected from \fIsignal\fR in this object.
.PP
\fBWarning:\fR This function violates the object-oriented principle of modularity. However, it might be useful for optimizing access to expensive resources.
.PP
See also disconnect() and connectNotify().
.SH "void QObject::dumpObjectInfo ()"
Dumps information about signal connections, etc. for this object to the debug output.
.PP
This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).
.SH "void QObject::dumpObjectTree ()"
Dumps a tree of children to the debug output.
.PP
This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).
.SH "bool QObject::event ( QEvent * e )\fC [virtual]\fR"
This virtual function receives events to an object and should return TRUE if the event \fIe\fR was recognized and processed.
.PP
The event() function can be reimplemented to customize the behavior of an object.
.PP
See also installEventFilter(), timerEvent(), QApplication::sendEvent(), QApplication::postEvent(), and QWidget::event().
Filters events if this object has been installed as an event filter for the \fIwatched\fR object.
.PP
In your reimplementation of this function, if you want to filter the event \fIe\fR, out, i.e. stop it being handled further, return TRUE; otherwise return FALSE.
Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.
\fBWarning:\fR If you delete the receiver object in this function, be sure to return TRUE. Otherwise, TQt will forward the event to the deleted object and the program might crash.
Inserts an object \fIobj\fR into the list of child objects.
.PP
\fBWarning:\fR This function cannot be used to make one widget the child widget of another widget. Child widgets can only be created by setting the parent widget in the constructor or by calling QWidget::reparent().
Installs an event filter \fIfilterObj\fR on this object. For example:
.PP
.nf
.br
monitoredObj->installEventFilter( filterObj );
.br
.fi
.PP
An event filter is an object that receives all events that are sent to this object. The filter can either stop the event or forward it to this object. The event filter \fIfilterObj\fR receives events via its eventFilter() function. The eventFilter() function must return TRUE if the event should be filtered, (i.e. stopped); otherwise it must return FALSE.
.PP
If multiple event filters are installed on a single object, the filter that was installed last is activated first.
.PP
Here's a \fCKeyPressEater\fR class that eats the key presses of its monitored objects:
\fBWarning:\fR If you delete the receiver object in your eventFilter() function, be sure to return TRUE. If you return FALSE, TQt sends the event to the deleted object and the program will crash.
Returns TRUE if this object is an instance of the class \fIclname\fR; otherwise returns FALSE.
.PP
Example:
.PP
.nf
.br
QTimer *t = new QTimer; // QTimer inherits QObject
.br
t->isA( "QTimer" ); // returns TRUE
.br
t->isA( "QObject" ); // returns FALSE
.br
.fi
.PP
See also inherits() and metaObject().
.SH "bool QObject::isWidgetType () const"
Returns TRUE if the object is a widget; otherwise returns FALSE.
.PP
Calling this function is equivalent to calling inherits("QWidget"), except that it is much faster.
.SH "void QObject::killTimer ( int id )"
Kills the timer with timer identifier, \fIid\fR.
.PP
The timer identifier is returned by startTimer() when a timer event is started.
.PP
See also timerEvent(), startTimer(), and killTimers().
.SH "void QObject::killTimers ()"
Kills all timers that this object has started.
.PP
\fBWarning:\fR Using this function can cause hard-to-find bugs: it kills timers started by sub- and superclasses as well as those started by you, which is often not what you want. We recommend using a QTimer or perhaps killTimer().
.PP
See also timerEvent(), startTimer(), and killTimer().
A meta object contains information about a class that inherits QObject, e.g. class name, superclass name, properties, signals and slots. Every class that contains the TQ_OBJECT macro will also have a meta object.
The meta object information is required by the signal/slot connection mechanism and the property system. The functions isA() and inherits() also make use of the meta object.
Searches the children and optionally grandchildren of this object, and returns a list of those objects that are named or that match \fIobjName\fR and inherit \fIinheritsClass\fR. If \fIinheritsClass\fR is 0 (the default), all classes match. If \fIobjName\fR is 0 (the default), all object names match.
.PP
If \fIregexpMatch\fR is TRUE (the default), \fIobjName\fR is a regular expression that the objects's names must match. The syntax is that of a QRegExp. If \fIregexpMatch\fR is FALSE, \fIobjName\fR is a string and object names must match it exactly.
Note that \fIinheritsClass\fR uses single inheritance from QObject, the way inherits() does. According to inherits(), QMenuBar inherits QWidget but not QMenuData. This does not quite match reality, but is the best that can be done on the wide variety of compilers TQt supports.
\fBWarning:\fR Delete the list as soon you have finished using it. The list contains pointers that may become invalid at almost any time without notice (as soon as the user closes a window you may have dangling pointers, for example).
.PP
See also child(), children(), parent(), inherits(), name, and QRegExp.
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. The pointer is valid only during the execution of the slot that calls this function.
.PP
The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.
.PP
\fBWarning:\fR This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot. The sender is undefined if the slot is called as a normal C++ function.
.SH "void QObject::setName ( const char * name )\fC [virtual]\fR"
Sets the value of the object's \fIname\fR property to \fIvalue\fR.
.PP
Returns TRUE if the operation was successful; otherwise returns FALSE.
.PP
Information about all available properties is provided through the metaObject().
.PP
See also property(), metaObject(), QMetaObject::propertyNames(), and QMetaObject::property().
.PP
Example: qutlook/centralwidget.cpp.
.SH "bool QObject::signalsBlocked () const"
Returns TRUE if signals are blocked; otherwise returns FALSE.
.PP
Signals are not blocked by default.
.PP
See also blockSignals().
.SH "int QObject::startTimer ( int interval )"
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.
.PP
A timer event will occur every \fIinterval\fR milliseconds until killTimer() or killTimers() is called. If \fIinterval\fR is 0, then the timer event occurs once every time there are no more window system events to process.
.PP
The virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.
.PP
If multiple timers are running, the QTimerEvent::timerId() can be used to find out which timer was activated.
Note that QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 20 ms; some provide more. If TQt is unable to deliver the requested number of timer clicks, it will silently discard some.
Returns a translated version of \fIsourceText\fR, or \fIsourceText\fR itself if there is no appropriate translated version. The translation context is QObject with \fIcomment\fR (0 by default). All QObject subclasses using the TQ_OBJECT macro automatically have a reimplementation of this function with the subclass name as context.
\fBWarning:\fR This method is reentrant only if all translators are installed \fIbefore\fR calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
.PP
See also trUtf8(), QApplication::translate(), and Internationalization with Qt.
Returns a translated version of \fIsourceText\fR, or QString::fromUtf8(\fIsourceText\fR) if there is no appropriate version. It is otherwise identical to tr(\fIsourceText\fR, \fIcomment\fR).
.PP
\fBWarning:\fR This method is reentrant only if all translators are installed \fIbefore\fR calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
.PP
See also tr() and QApplication::translate().
.SS "Property Documentation"
.SH "QCString name"
This property holds the name of this object.
.PP
You can find an object by name (and type) using child(). You can find a set of objects with queryList().
.PP
The object name is set by the constructor or by the setName() function. The object name is not very useful in the current version of Qt, but will become increasingly important in the future.
If the object does not have a name, the name() function returns" unnamed", so printf() (used in tqDebug()) will not be asked to output a null pointer. If you want a null pointer to be returned for unnamed objects, you can call name( 0 ).