Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The TQObject class is the base class of all TQt objects. More...
All the functions in this class are reentrant when TQt is built with thread support.
#include <ntqobject.h>
Inherits TQt.
Inherited by TQAccel, TQAccessibleObject, TQAction, TQApplication, TQAssistantClient, TQDataPump, TQAxObject, TQAxScript, TQAxScriptManager, TQWidget, TQCanvas, TQStyle, TQClipboard, TQCopChannel, TQDns, TQLayout, TQDragObject, TQEditorFactory, TQEventLoop, TQFileIconProvider, TQNetworkProtocol, TQWSKeyboardHandler, TQNetworkOperation, TQNPInstance, TQObjectCleanupHandler, TQProcess, TQServerSocket, TQSessionManager, TQSignal, TQSignalMapper, TQSocket, TQSocketNotifier, TQSound, TQSqlDatabase, TQSqlDriver, TQSqlForm, TQStyleSheet, TQTimer, TQToolTipGroup, TQTranslator, TQUrlOperator, and TQValidator.
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().
Every object has an object name() and can report its className() and whether it inherits() another class in the TQObject inheritance hierarchy.
When an object is deleted, it emits a destroyed() signal. You can catch this signal to avoid dangling references to TQObjects. The TQGuardedPtr 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.
Last but not least, TQObject provides the basic timer support in TQt; see TQTimer 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 all 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.
See also Object Model.
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.
The destructor of a parent object destroys all child objects.
Setting parent to 0 constructs an object with no parent. If the object is a widget, it will become a top-level window.
The object name is some text that can be used to identify a TQObject. It's particularly useful in conjunction with TQt Designer. You can find an object by name (and type) using child(). To find several objects use queryList().
See also parent(), name, child(), and queryList().
All signals to and from the object are automatically disconnected.
Warning: 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.
Warning: 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.
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.
Examples: rot13/rot13.cpp and simple/main.cpp.
Returns TRUE if the signal and the member arguments are compatible; otherwise returns FALSE. (The receiver argument is currently ignored.)
Warning: We recommend that you use the default implementation and do not reimplement this function.
If recursiveSearch is TRUE (the default), child() performs a depth-first search of the object's children.
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().
Child events are sent to objects when children are inserted or removed.
Note that events with TQEvent::type() TQEvent::ChildInserted are posted (with TQApplication::postEvent()) to make sure that the child's construction is completed before this function is called.
If a child is removed immediately after it is inserted, the ChildInserted event may be suppressed, but the ChildRemoved event will always be sent. In such cases it is possible that there will be a ChildRemoved event without a corresponding ChildInserted event.
If you change state based on ChildInserted events, call TQWidget::constPolish(), or do
TQApplication::sendPostedEvents( this, TQEvent::ChildInserted );in functions that depend on the state. One notable example is TQWidget::sizeHint().
See also event() and TQChildEvent.
Reimplemented in TQMainWindow and TQSplitter.
Returns a list of child objects, or 0 if this object has no children.
The TQObjectList class is defined in the ntqobjectlist.h header file.
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.
See also child(), queryList(), parent(), insertChild(), and removeChild().
Returns the class name of this object.
This function is generated by the Meta Object Compiler.
Warning: This function will return the wrong name if the class definition lacks the TQ_OBJECT macro.
See also name, inherits(), isA(), and isWidgetType().
Example: sql/overview/custom1/main.cpp.
You must use the SIGNAL() and SLOT() macros when specifying the signal and the member, for example:
TQLabel *label = new TQLabel; TQScrollBar *scroll = new TQScrollBar; TQObject::connect( scroll, SIGNAL(valueChanged(int)), label, SLOT(setNum(int)) );
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, SIGNAL(valueChanged(int v)), label, SLOT(setNum(int v)) );
A signal can also be connected to another signal:
class MyWidget : public TQWidget { TQ_OBJECT public: MyWidget(); signals: void myUsefulSignal(); private: TQPushButton *aButton; }; MyWidget::MyWidget() { aButton = new TQPushButton( this ); connect( aButton, SIGNAL(clicked()), SIGNAL(myUsefulSignal()) ); }
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.
A signal can be connected to many slots and signals. Many signals can be connected to one slot.
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 signal or member, or if their signatures aren't compatible.
A signal is emitted for every connection you make, so if you duplicate a connection, two signals will be emitted. You can always break a connection using disconnect().
See also disconnect().
Examples: action/main.cpp, application/main.cpp, extension/main.cpp, iconview/main.cpp, network/archivesearch/main.cpp, regexptester/main.cpp, and t2/main.cpp.
Connects signal from the sender object to this object's member.
Equivalent to: TQObject::connect(sender, signal, this, member).
See also disconnect().
This virtual function is called when something has been connected to signal in this object.
Warning: 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.
See also connect() and disconnectNotify().
See also event() and TQCustomEvent.
Instead of an immediate deletion this function schedules a deferred delete event for processing when TQt returns to the main event loop.
Example: table/bigtable/main.cpp.
This signal is emitted when the object is being destroyed.
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.
All the objects's children are destroyed immediately after this signal is emitted.
This signal is emitted immediately before the object obj is destroyed, and can not be blocked.
All the objects's children are destroyed immediately after this signal is emitted.
A signal-slot connection is removed when either of the objects involved are destroyed.
disconnect() is typically used in three ways, as the following examples demonstrate.
disconnect( myObject, 0, 0, 0 );equivalent to the non-static overloaded function
myObject->disconnect();
disconnect( myObject, SIGNAL(mySignal()), 0, 0 );equivalent to the non-static overloaded function
myObject->disconnect( SIGNAL(mySignal()) );
disconnect( myObject, 0, myReceiver, 0 );equivalent to the non-static overloaded function
myObject->disconnect( myReceiver );
0 may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively.
The sender may never be 0. (You cannot disconnect signals from more than one object in a single call.)
If signal is 0, it disconnects receiver and member from any signal. If not, only the specified signal is disconnected.
If receiver is 0, it disconnects anything connected to signal. If not, slots in objects other than receiver are not disconnected.
If member is 0, it disconnects anything that is connected to receiver. If not, only slots named member will be disconnected, and all other slots are left alone. The member must be 0 if receiver is left out, so you cannot disconnect a specifically-named slot on all objects.
See also connect().
Disconnects signal from member of receiver.
A signal-slot connection is removed when either of the objects involved are destroyed.
Disconnects all signals in this object from receiver's member.
A signal-slot connection is removed when either of the objects involved are destroyed.
This virtual function is called when something has been disconnected from signal in this object.
Warning: This function violates the object-oriented principle of modularity. However, it might be useful for optimizing access to expensive resources.
See also disconnect() and connectNotify().
This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).
This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).
The event() function can be reimplemented to customize the behavior of an object.
See also installEventFilter(), timerEvent(), TQApplication::sendEvent(), TQApplication::postEvent(), and TQWidget::event().
Reimplemented in TQWidget.
In your reimplementation of this function, if you want to filter the event e, out, i.e. stop it being handled further, return TRUE; otherwise return FALSE.
Example:
class MyMainWindow : public TQMainWindow { public: MyMainWindow( TQWidget *parent = 0, const char *name = 0 ); protected: bool eventFilter( TQObject *obj, TQEvent *ev ); private: TQTextEdit *textEdit; }; MyMainWindow::MyMainWindow( TQWidget *parent, const char *name ) : TQMainWindow( parent, name ) { textEdit = new TQTextEdit( this ); setCentralWidget( textEdit ); textEdit->installEventFilter( this ); } bool MyMainWindow::eventFilter( TQObject *obj, TQEvent *ev ) { if ( obj == textEdit ) { if ( e->type() == TQEvent::KeyPress ) { TQKeyEvent *k = (TQKeyEvent*)ev; qDebug( "Ate key press %d", k->key() ); return TRUE; } else { return FALSE; } } else { // pass the event on to the parent class return TQMainWindow::eventFilter( obj, ev ); } }
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.
Warning: 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.
See also installEventFilter().
Reimplemented in TQAccel, TQScrollView, and TQSpinBox.
Returns TRUE if the object is a high-priority object, or FALSE if it is a standard-priority object.
High-priority objects are placed first in TQObject's list of children on the assumption that they will be referenced very often.
A class is considered to inherit itself.
Example:
TQTimer *t = new TQTimer; // TQTimer inherits TQObject t->inherits( "TQTimer" ); // returns TRUE t->inherits( "TQObject" ); // returns TRUE t->inherits( "TQButton" ); // returns FALSE // TQScrollBar inherits TQWidget and TQRangeControl TQScrollBar *s = new TQScrollBar( 0 ); s->inherits( "TQWidget" ); // returns TRUE s->inherits( "TQRangeControl" ); // returns FALSE
(TQRangeControl is not a TQObject.)
See also isA() and metaObject().
Examples: table/statistics/statistics.cpp, themes/metal.cpp, and themes/wood.cpp.
Warning: 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().
See also removeChild() and TQWidget::reparent().
Installs an event filter filterObj on this object. For example:
monitoredObj->installEventFilter( filterObj );
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 filterObj 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.
If multiple event filters are installed on a single object, the filter that was installed last is activated first.
Here's a KeyPressEater class that eats the key presses of its monitored objects:
class KeyPressEater : public TQObject { ... protected: bool eventFilter( TQObject *o, TQEvent *e ); }; bool KeyPressEater::eventFilter( TQObject *o, TQEvent *e ) { if ( e->type() == TQEvent::KeyPress ) { // special processing for key press TQKeyEvent *k = (TQKeyEvent *)e; qDebug( "Ate key press %d", k->key() ); return TRUE; // eat event } else { // standard event processing return FALSE; } }
And here's how to install it on two widgets:
KeyPressEater *keyPressEater = new KeyPressEater( this ); TQPushButton *pushButton = new TQPushButton( this ); TQListView *listView = new TQListView( this ); pushButton->installEventFilter( keyPressEater ); listView->installEventFilter( keyPressEater );
The TQAccel class, for example, uses this technique to intercept accelerator key presses.
Warning: 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.
See also removeEventFilter(), eventFilter(), and event().
Example:
TQTimer *t = new TQTimer; // TQTimer inherits TQObject t->isA( "TQTimer" ); // returns TRUE t->isA( "TQObject" ); // returns FALSE
See also inherits() and metaObject().
Returns TRUE if the object is a widget; otherwise returns FALSE.
Calling this function is equivalent to calling inherits("TQWidget"), except that it is much faster.
The timer identifier is returned by startTimer() when a timer event is started.
See also timerEvent(), startTimer(), and killTimers().
Warning: 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().
See also timerEvent(), startTimer(), and killTimer().
Returns a pointer to the meta object of this object.
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.
Returns the name of this object. See the "name" property for details.
Returns the name of this object, or defaultName if the object does not have a name.
The TQObjectList class is defined in the ntqobjectlist.h header file.
The most recent root object created is the first object in the list and the first root object added is the last object in the list.
See also children(), parent(), insertChild(), and removeChild().
Returns a pointer to the parent object.
See also children().
If no such property exists, the returned variant is invalid.
Information about all available properties are provided through the metaObject().
See also setProperty(), TQVariant::isValid(), metaObject(), TQMetaObject::propertyNames(), and TQMetaObject::property().
Example: qutlook/centralwidget.cpp.
If regexpMatch is TRUE (the default), objName is a regular expression that the objects's names must match. The syntax is that of a TQRegExp. If regexpMatch is FALSE, objName is a string and object names must match it exactly.
Note that inheritsClass uses single inheritance from TQObject, the way inherits() does. According to inherits(), TQMenuBar inherits TQWidget but not TQMenuData. This does not quite match reality, but is the best that can be done on the wide variety of compilers TQt supports.
Finally, if recursiveSearch is TRUE (the default), queryList() searches nth-generation as well as first-generation children.
If all this seems a bit complex for your needs, the simpler child() function may be what you want.
This somewhat contrived example disables all the buttons in this window:
TQObjectList *l = topLevelWidget()->queryList( "TQButton" ); TQObjectListIt it( *l ); // iterate over the buttons TQObject *obj; while ( (obj = it.current()) != 0 ) { // for each found object... ++it; ((TQButton*)obj)->setEnabled( FALSE ); } delete l; // delete the list, not the objects
The TQObjectList class is defined in the ntqobjectlist.h header file.
Warning: 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).
See also child(), children(), parent(), inherits(), name, and TQRegExp.
Warning: This function will not remove a child widget from the screen. It will only remove it from the parent widget's list of children.
See also insertChild() and TQWidget::reparent().
All event filters for this object are automatically removed when this object is destroyed.
It is always safe to remove an event filter, even during event filter activation (i.e. from the eventFilter() function).
See also installEventFilter(), eventFilter(), and event().
The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.
Warning: 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.
Returns TRUE if the operation was successful; otherwise returns FALSE.
Information about all available properties is provided through the metaObject().
See also property(), metaObject(), TQMetaObject::propertyNames(), and TQMetaObject::property().
Example: qutlook/centralwidget.cpp.
Returns TRUE if signals are blocked; otherwise returns FALSE.
Signals are not blocked by default.
See also blockSignals().
A timer event will occur every interval milliseconds until killTimer() or killTimers() is called. If interval 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.
If multiple timers are running, the TQTimerEvent::timerId() can be used to find out which timer was activated.
Example:
class MyObject : public TQObject { TQ_OBJECT public: MyObject( TQObject *parent = 0, const char *name = 0 ); protected: void timerEvent( TQTimerEvent * ); }; MyObject::MyObject( TQObject *parent, const char *name ) : TQObject( parent, name ) { startTimer( 50 ); // 50-millisecond timer startTimer( 1000 ); // 1-second timer startTimer( 60000 ); // 1-minute timer } void MyObject::timerEvent( TQTimerEvent *e ) { qDebug( "timer event, id %d", e->timerId() ); }
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.
The TQTimer class provides a high-level programming interface with one-shot timers and timer signals instead of events.
See also timerEvent(), killTimer(), killTimers(), TQEventLoop::awake(), and TQEventLoop::aboutToBlock().
TQTimer provides a higher-level interface to the timer functionality, and also more general information about timers.
See also startTimer(), killTimer(), killTimers(), and event().
Examples: biff/biff.cpp, dclock/dclock.cpp, forever/forever.cpp, grapher/grapher.cpp, qmag/qmag.cpp, and xform/xform.cpp.
Returns a translated version of sourceText, or sourceText itself if there is no appropriate translated version. The translation context is TQObject with comment (0 by default). All TQObject subclasses using the TQ_OBJECT macro automatically have a reimplementation of this function with the subclass name as context.
Warning: This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
See also trUtf8(), TQApplication::translate(), and Internationalization with TQt.
Example: network/networkprotocol/view.cpp.
Returns a translated version of sourceText, or TQString::fromUtf8(sourceText) if there is no appropriate version. It is otherwise identical to tr(sourceText, comment).
Warning: This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
See also tr() and TQApplication::translate().
This property holds the name of this object.
You can find an object by name (and type) using child(). You can find a set of objects with queryList().
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 TQt, 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 qDebug()) 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 ).
qDebug( "MyClass::setPrecision(): (%s) invalid precision %f", name(), newPrecision );
See also className(), child(), and queryList().
Set this property's value with setName() and get this property's value with name().
Returns a pointer to the object named name that inherits type and with a given parent.
Returns 0 if there is no such child.
TQListBox *c = (TQListBox *) qt_find_obj_child( myWidget, "TQListBox", "my list box" ); if ( c ) c->insertItem( "another string" );
This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | TQt 3.3.8
|