📄 qobject.3qt
字号:
.br.br class MyWidget : public QWidget.br {.br public:.br MyWidget::MyWidget( QWidget *parent=0, const char *name=0 );.br protected:.br bool eventFilter( QObject *, QEvent * );.br };.br.br MyWidget::MyWidget( QWidget *parent, const char *name ).br : QWidget( parent, name ).br {.br if ( parent ) // has a parent widget.br parent->installEventFilter( this ); // then install filter.br }.br.br bool MyWidget::eventFilter( QObject *, QEvent *e ).br {.br if ( e->type() == QEvent::KeyPress ) { // key press.br QKeyEvent *k = (QKeyEvent*)e;.br qDebug( "Ate key press %d", k->key() );.br return TRUE; // eat event.br }.br return FALSE; // standard event processing.br }.fi.PPThe QAccel class was implemented using 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..PPUsing this function makes it harder to subclass your class (it kills timers started by subclasses as well as those started by you), so it is generally better to use killTimer()..PPSee also: timerEvent(), startTimer() and killTimer()..PPExamples:.(lxform/xform.cpp qmag/qmag.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, 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. The functions isA() and inherits() also make use of the meta object..PPThe meta object is created by the initMetaObject() function, which is generated by the meta object compiler and called from the QObject constructor..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 debug()) 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..PPThe queryList() function searches the object tree for objects that matches a particular object name..PPSee also: setName(), className() 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 "QObject * QObject::parent () const"Returns a pointer to the parent object..PPSee also: children()..SH "QObjectList * QObject::queryList ( const char * inheritsClass = 0, const char * objName = 0, bool regexpMatch = TRUE, bool recursiveSearch = TRUE )"Returns a list of child objects found by a query..PPThe query is specified by:.PPArguments:.TP\fIinheritsClass\fR is the name of the base class that an object should inherit. Any class will be matched if \fIinheritsClass\fR is 0..TP\fIobjName\fR is the object name to search for. Any object name will be matched if \fIobjName\fR is 0..TP\fIregexpMatch\fR specifies whether \fIobjName\fR is a regular expression (default) or not..TP\fIrecursiveSearch\fR must be \fCTRUE\fR (default) if you want to search the entire object tree, or \fCFALSE\fR if you want the search to traverse just the 1st level child objects of this object. Example:.PP.nf.br //.br // Sets a Courier 24 point fonts for all children in myWidget that.br // inherit QButton (i.e. QPushButton, QCheckBox, QRadioButton)..br //.br QObjectList *list = myWidget->queryList( "QButton" );.br QObjectListIt it( *list ); // iterate over the buttons.br QFont newFont( "Courier", 24 );.br QObject * obj;.br while ( (obj=it.current()) != 0 ) { // for each found object....br ++it;.br ((QButton*)obj)->setFont( newFont );.br }.br delete list; // delete the list, not the objects.fi.PPThe QObjectList class is defined in the qobjcoll.h header file..PP\fBWarning:\fR Delete the list away as soon you have finished using it. You can get in serious trouble if you for instance try to access an object that has been deleted..PPSee also: 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 last signal received by this object..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..PPThe object name is not very useful in the current version of Qt, but it will become increasingly important in the future..PPThe queryList() function searches the object tree for objects that matches a particular object name..PPSee also: name(), className() and queryList()..PPReimplemented in QWidget and QSignal..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:.(lxform/xform.cpp qmag/qmag.cpp forever/forever.cpp.)l.SH "void QObject::staticMetaObject () \fC[static protected]\fR"The functionality of initMetaObject(), provided as a static function..SH "QStringList QObject::superClasses ( bool includeThis = FALSE ) const"Returns a list of all super classes. If \fIincludeThis\fR is TRUE then the most derived class name of this object is added, too. The most derived classes appear first in the list. That means that QObject is always the last entry in the list..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 QSocket, QPopupMenu and QMultiLineEdit..SH "QString QObject::tr ( const char * text ) \fC[static]\fR"Returns a translated version of \fItext,\fR or \fItext\fR if there is no appropriate translated version. All QObject subclasses which use the Q_OBJECT macro have an overridden version of this..PPSee also: QApplication::translate()..PPExamples:.(lxform/xform.cpp.)l.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://www.troll.no/qt/qobject.html.SH COPYRIGHTCopyright 1992-1999 Troll Tech AS. See the license file included inthe distribution for a complete license statement..SH AUTHORGenerated automatically from the source code.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -