📄 qobject.3qt
字号:
return TRUE; // eat event.br }.br return QWidget::eventFilter( o, e ); // standard event processing.br }.fi.PPThe QAccel class, for example, uses this technique..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 a specified class, otherwise FALSE..PPExample:.PP.nf.br QTimer *t = new QTimer; // QTimer inherits QObject.br t->isA("QTimer"); // returns TRUE.br t->isA("QObject"); // returns FALSE.fi.PPSee also inherits() and metaObject()..SH "bool QObject::isWidgetType () const"Returns TRUE if the object is a widget, or FALSE if not..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 the identifier \fIid.\fR.PPThe timer identifier is returned by startTimer() when a timer event is started..PPSee also timerEvent(), startTimer() and killTimers()..PPExamples:.(lgrapher/grapher.cpp.)l.SH "void QObject::killTimers ()"Kills all timers that this object has started..PPNote that 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. Therefore, we recommend using a QTimer, or perhaps killTimer()..PPSee also timerEvent(), startTimer() and killTimer()..PPExamples:.(lqmag/qmag.cpp xform/xform.cpp.)l.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: class name, super class name, properties, signals and slots. Every class that contains the \fCQ_OBJECT\fR 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. If the object does not have a name, it will return "unnamed", so that 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) unable to set precision to %f",.br name(), newPrecision );.fi.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..PPYou can find an object by name (and type) using child(), and more than one using queryList()..PPSee also setName(), className(), child() and queryList()..SH "const char * QObject::name ( const char * defaultName ) const"Returns 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 whitespaces..SH "const QObjectList * QObject::objectTrees () \fC[static]\fR"Returns a pointer to the list of all object trees (respectively their root objects), or 0 if there are no objects..PPThe QObjectList class is defined in the qobjectlist.h header file..PPThe latest 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"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()..SH "QObjectList * QObject::queryList ( const char * inheritsClass = 0, const char * objName = 0, bool regexpMatch = TRUE, bool recursiveSearch = TRUE )"Searches the children and optinally grandchildren of this object, and returns a list of those objects that are named or matches \fIobjName\fR and inherit \fIineritsClass.\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 regexp that the objects's names must match. If \fIregexpMatch\fR is FALSE, \fIobjName\fR is a string and object names must match it exactly..PPNote that \fIineritsClass\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 nth-generation as well as first-generation children..PPIf all this seems a bit complex for your needs, the simpler function child() 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 while ( (obj=it.current()) != 0 ) { // for each found object....br ++it;.br ((QButton*)obj)->setEnabled( FALSE );.br }.br delete l; // delete the list, not the objects.fi.PP\fBWarning:\fR Delete the list away 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 "QConnectionList * QObject::receivers ( const char * signal ) const \fC[protected]\fR"Returns a list of objects/slot pairs that are connected to the signal, or 0 if nothing is connected to it..PPThis function is for internal use..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()..PPReimplemented in QScrollView..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 before any function call or signal emission. Returns an undefined value in all other cases..PP\fBWarning:\fR This function will return something apparently correct in other cases as well. However, its value may change during any function call, depending on what signal-slot connections are activated during that call. In Qt 3.0 the value will change more often than in 2.x..PP\fBWarning:\fR This function violates the object-oriented principle of modularity, However, getting access to the sender might be practical 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 name of this object to \fIname.\fR The default name is the one assigned by the constructor..PPYou can find an object by name (and type) using child(), and more than one using queryList()..PPSee also name(), className(), queryList() and child()..PPReimplemented in QSignal and QWidget..SH "bool QObject::setProperty ( const char * name, const QVariant & value )"Sets the object's property \fIname\fR to \fIvalue.\fR.PPReturne TRUE is the operation was successful, FALSE otherwise..PPInformation about all available properties are provided through the metaObject()..PPSee also property(), metaObject(), QMetaObject::propertyNames() and QMetaObject::property()..SH "bool QObject::signalsBlocked () const"Returns TRUE if signals are blocked, or FALSE if signals are not blocked..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 public:.br MyObject( QObject *parent=0, const char *name=0 );.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 }.fi.PPThere is practically no upper limit for the interval value (more than one year). The accuracy depends on the underlying operating system. Windows 95 has 55 millisecond (18.2 times per second) accuracy; other systems that we have tested (UNIX X11, Windows NT and OS/2) can handle 1 millisecond intervals..PPThe QTimer class provides a high-level programming interface with one-shot timers and timer signals instead of events..PPSee also timerEvent(), killTimer() and killTimers()..PPExamples:.(lforever/forever.cpp qmag/qmag.cpp.)l.SH "QMetaObject* QObject::staticMetaObject () \fC[static protected]\fR"The functionality of initMetaObject(), provided as a static function..SH "QStringList QObject::superClasses ( bool includeThis = FALSE ) const"\fBThis function is obsolete.\fR It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code..PPThis function is misleadingly named, and cannot be implemented in a way that fulfills its name. someQWidget->superClasses() should have returned QPaintDevice and QObject, obviously. And it never can, so let us kill the function. \fBIt will be removed in Qt-3.0\fR.PPOh, and the return type was wrong, too. QStringList not QStrList..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()..PPReimplemented in QMultiLineEdit and QPopupMenu..SH "QString QObject::tr ( const char * text, const char * comment ) \fC[static]\fR"Returns a translated version of \fItext\fR in context QObject and and with \fIcomment,\fR or \fItext\fR if there is no appropriate translated version. All QObject subclasses which use the Q_OBJECT macro have a reimplementation of this function which uses the relevant class name as context..PPSee also QApplication::translate()..SH "QString QObject::tr ( const char * text ) \fC[static]\fR"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPReturns a translated version of \fItext\fR in context QObject and with no comment, or \fItext\fR if there is no appropriate translated version. All QObject subclasses which use the Q_OBJECT macro have a reimplementation of this function which uses the relevant class name as context..PPSee also QApplication::translate()..SH "bool QObject::activate_filters ( QEvent * e ) \fC[protected]\fR"For internal use only..SH "void QObject::activate_signal ( const char * signal ) \fC[protected]\fR"For internal use only..SH RELATED FUNCTION DOCUMENTATION.SH "void * qt_find_obj_child (QObject * parent, const char * type, const char * name)"Returns a pointer to the child named \fIname\fR of QObject \fIparent\fR which inherits type \fItype.\fR.PPReturns 0 if there is no such child..PP.nf.br QListBox * c = (QListBox *)::qt_find_obj_child(myWidget,QListBox,.br "listboxname");.br if ( c ).br c->insertItem( "another string" );.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 make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qobject.3qt) and the Qtversion (2.3.10).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -