TQObject 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.
TQObjects organize themselves in object trees. When you create a TQObject 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().
When an object is deleted, it emits a destroyed() signal. You can catch this signal to avoid dangling references to TQObjects. The QGuardedPtr class provides an elegant way to use this feature.
TQObjects 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.
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 TQObject 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 TQObject. The convenience function isWidgetType() returns whether an object is actually a widget. It is much faster than inherits( "TQWidget" ).
Some TQObject functions, e.g. children(), objectTrees() and queryList() return a TQObjectList. A TQObjectList is a TQPtrList of TQObjects. TQObjectLists support the same operations as TQPtrLists and have an iterator class, TQObjectListIt.
The object name is some text that can be used to identify a TQObject. 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().
\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 TQObject::destroyed() signal gives you an opportunity to detect when an object is destroyed.
\fBWarning:\fR Deleting a TQObject while pending events are waiting to be delivered can cause a crash. You must not delete the TQObject directly from a thread that is not the GUI thread. Use the TQObject::deleteLater() method instead, which will cause the event loop to delete the object after all pending events have been delivered to the object.
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.
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.
Note that the list order changes when TQWidget 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.
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.
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: TQObject::connect( scroll, TQ_SIGNAL(valueChanged(int v)), label, TQ_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.
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 TQObject is unable to verify the existence of either \fIsignal\fR or \fImember\fR, or if their signatures aren't compatible.
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.
Note that the signal is emitted by the TQObject 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.
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.
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.
\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 TQWidget::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.
\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 TQTimer or perhaps killTimer().
A meta object contains information about a class that inherits TQObject, 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 TQObject, the way inherits() does. According to inherits(), QMenuBar inherits TQWidget 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.
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.
The virtual timerEvent() function is called with the TQTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.
Note that TQTimer'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 TQObject with \fIcomment\fR (0 by default). All TQObject 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 TQString::fromUtf8(\fIsourceText\fR) if there is no appropriate version. It is otherwise identical to tr(\fIsourceText\fR, \fIcomment\fR).
\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 ).