📄 qobject.3qt
字号:
qDebug( "Ate key press %d", k->key() );.br return TRUE; // eat event.br } else {.br // standard event processing.br return FALSE;.br }.br }.br.fi.PPAnd here's how to install it on two widgets:.PP.nf.br KeyPressEater *keyPressEater = new KeyPressEater( this );.br QPushButton *pushButton = new QPushButton( this );.br QListView *listView = new QListView( this );.br.br pushButton->installEventFilter( keyPressEater );.br listView->installEventFilter( keyPressEater );.br.fi.PPThe QAccel class, for example, uses this technique to intercept accelerator key presses..PP\fBWarning:\fR If you delete the receiver object in your eventFilter() function, be sure to return TRUE. If you return FALSE, Qt sends the event to the deleted object and the program will crash..PPSee also removeEventFilter(), eventFilter(), and event()..SH "bool QObject::isA ( const char * clname ) const"Returns TRUE if this object is an instance of the class \fIclname\fR; otherwise returns FALSE..PPExample:.PP.nf.br QTimer *t = new QTimer; // QTimer inherits QObject.br t->isA( "QTimer" ); // returns TRUE.br t->isA( "QObject" ); // returns FALSE.br.fi.PPSee also inherits() and metaObject()..SH "bool QObject::isWidgetType () const"Returns TRUE if the object is a widget; otherwise returns FALSE..PPCalling 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..PPThe timer identifier is returned by startTimer() when a timer event is started..PPSee 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()..PPSee also timerEvent(), startTimer(), and killTimer()..SH "QMetaObject * QObject::metaObject () const\fC [virtual]\fR"Returns a pointer to the meta object of this object..PPA 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 Q_OBJECT macro will also have a meta object..PPThe 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..SH "const char * QObject::name () const"Returns the name of this object. See the "name" property for details..SH "const char * QObject::name ( const char * defaultName ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the name of this object, or \fIdefaultName\fR if the object does not have a name..SH "QCString QObject::normalizeSignalSlot ( const char * signalSlot )\fC [static protected]\fR"Normlizes the signal or slot definition \fIsignalSlot\fR by removing unnecessary whitespace..SH "const QObjectList * QObject::objectTrees ()\fC [static]\fR"Returns a pointer to the list of all object trees (their root objects), or 0 if there are no objects..PPThe QObjectList class is defined in the qobjectlist.h header file..PPThe 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..PPSee also children(), parent(), insertChild(), and removeChild()..SH "QObject * QObject::parent () const"Returns a pointer to the parent object..PPSee also children()..SH "QVariant QObject::property ( const char * name ) const\fC [virtual]\fR"Returns the value of the object's \fIname\fR property..PPIf no such property exists, the returned variant is invalid..PPInformation about all available properties are provided through the metaObject()..PPSee also setProperty(), QVariant::isValid(), metaObject(), QMetaObject::propertyNames(), and QMetaObject::property()..PPExample: qutlook/centralwidget.cpp..SH "QObjectList * QObject::queryList ( const char * inheritsClass = 0, const char * objName = 0, bool regexpMatch = TRUE, bool recursiveSearch = TRUE ) const"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..PPIf \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..PPNote 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 Qt supports..PPFinally, if \fIrecursiveSearch\fR is TRUE (the default), queryList() searches \fIn\fRth-generation as well as first-generation children..PPIf all this seems a bit complex for your needs, the simpler child() function may be what you want..PPThis somewhat contrived example disables all the buttons in this window:.PP.nf.br QObjectList *l = topLevelWidget()->queryList( "QButton" );.br QObjectListIt it( *l ); // iterate over the buttons.br QObject *obj;.br.br while ( (obj = it.current()) != 0 ) {.br // for each found object....br ++it;.br ((QButton*)obj)->setEnabled( FALSE );.br }.br delete l; // delete the list, not the objects.br.fi.PPThe QObjectList class is defined in the qobjectlist.h header file..PP\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)..PPSee also child(), children(), parent(), inherits(), name, and QRegExp..SH "void QObject::removeChild ( QObject * obj )\fC [virtual]\fR"Removes the child object \fIobj\fR from the list of children..PP\fBWarning:\fR This function will not remove a child widget from the screen. It will only remove it from the parent widget's list of children..PPSee also insertChild() and QWidget::reparent()..SH "void QObject::removeEventFilter ( const QObject * obj )"Removes an event filter object \fIobj\fR from this object. The request is ignored if such an event filter has not been installed..PPAll event filters for this object are automatically removed when this object is destroyed..PPIt is always safe to remove an event filter, even during event filter activation (i.e. from the eventFilter() function)..PPSee also installEventFilter(), eventFilter(), and event()..SH "const QObject * QObject::sender ()\fC [protected]\fR"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..PPThe 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 object's name to \fIname\fR..SH "bool QObject::setProperty ( const char * name, const QVariant & value )\fC [virtual]\fR"Sets the value of the object's \fIname\fR property to \fIvalue\fR..PPReturns TRUE if the operation was successful; otherwise returns FALSE..PPInformation about all available properties is provided through the metaObject()..PPSee also property(), metaObject(), QMetaObject::propertyNames(), and QMetaObject::property()..PPExample: qutlook/centralwidget.cpp..SH "bool QObject::signalsBlocked () const"Returns TRUE if signals are blocked; otherwise returns FALSE..PPSignals are not blocked by default..PPSee 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..PPA 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..PPThe virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events..PPIf multiple timers are running, the QTimerEvent::timerId() can be used to find out which timer was activated..PPExample:.PP.nf.br class MyObject : public QObject.br {.br Q_OBJECT.br public:.br MyObject( QObject *parent = 0, const char *name = 0 );.br.br protected:.br void timerEvent( QTimerEvent * );.br };.br.br MyObject::MyObject( QObject *parent, const char *name ).br : QObject( parent, name ).br {.br startTimer( 50 ); // 50-millisecond timer.br startTimer( 1000 ); // 1-second timer.br startTimer( 60000 ); // 1-minute timer.br }.br.br void MyObject::timerEvent( QTimerEvent *e ).br {.br qDebug( "timer event, id %d", e->timerId() );.br }.br.fi.PPNote that QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 20 ms; some provide more. If Qt is unable to deliver the requested number of timer clicks, it will silently discard some..PPThe QTimer class provides a high-level programming interface with one-shot timers and timer signals instead of events..PPSee also timerEvent(), killTimer(), killTimers(), QEventLoop::awake(), and QEventLoop::aboutToBlock()..SH "void QObject::timerEvent ( QTimerEvent * )\fC [virtual protected]\fR"This event handler can be reimplemented in a subclass to receive timer events for the object..PPQTimer provides a higher-level interface to the timer functionality, and also more general information about timers..PPSee also startTimer(), killTimer(), killTimers(), and event()..PPExamples:.)l dclock/dclock.cpp, forever/forever.cpp, grapher/grapher.cpp, qmag/qmag.cpp, and xform/xform.cpp..SH "QString QObject::tr ( const char * sourceText, const char * comment )\fC [static]\fR"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 Q_OBJECT macro automatically have a reimplementation of this function with the subclass name as context..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..PPSee also trUtf8(), QApplication::translate(), and Internationalization with Qt..PPExample: network/networkprotocol/view.cpp..SH "QString QObject::trUtf8 ( const char * sourceText, const char * comment )\fC [static]\fR"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..PPSee also tr() and QApplication::translate()..SS "Property Documentation".SH "QCString name"This property holds the name of this object..PPYou can find an object by name (and type) using child(). You can find a set of objects with queryList()..PPThe 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..PPIf 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 )..PP.nf.br qDebug( "MyClass::setPrecision(): (%s) invalid precision %f",.br name(), newPrecision );.br.fi.PPSee also className(), child(), and queryList()..PPSet this property's value with setName() and get this property's value with name()..SH RELATED FUNCTION DOCUMENTATION.SH "void * qt_find_obj_child ( QObject * parent, const char * type, const char * name )"Returns a pointer to the object named \fIname\fR that inherits \fItype\fR and with a given \fIparent\fR..PPReturns 0 if there is no such child..PP.nf.br QListBox *c = (QListBox *) qt_find_obj_child( myWidget, "QListBox",.br "my list box" );.br if ( c ).br c->insertItem( "another string" );.br.fi.SH "SEE ALSO".BR http://doc.trolltech.com/qobject.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qobject.3qt) and the Qtversion (3.3.5).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -