📄 qobject.3qt
字号:
Returns a list of child objects, or 0 if this object has no children..PPThe QObjectList class is defined in the qobjectlist.h header file..PPThe latest child added is the first object in the list and the first child added is the last object in the list..PPNote that the list order changes when QWidget 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..PPSee also child(), queryList(), parent(), insertChild() and removeChild()..SH "const char * QObject::className () const \fC[virtual]\fR"Returns the class name of this object..PPThis function is generated by the Meta Object Compiler..PP\fBWarning:\fR This function will return an invalid name if the class definition lacks the \fCQ_OBJECT\fR macro..PPSee also name(), inherits(), isA() and isWidgetType()..SH "bool QObject::connect ( const QObject * sender, const char * signal, const QObject * receiver, const char * member ) \fC[static]\fR"Connects \fIsignal\fR from the \fIsender\fR object to \fImember\fR in object \fIreceiver.\fR.PPYou must use the SIGNAL() and SLOT() macros when specifying the \fIsignal\fR and the \fImember.\fR.PPExample:.PP.nf.br QLabel *label = new QLabel;.br QScrollBar *scroll = new QScrollBar;.br QObject::connect( scroll, SIGNAL(valueChanged(int)),.br label, SLOT(setNum(int)) );.fi.PPThis example connects the scroll bar's valueChanged() signal to the label's setNum() slot. It makes the label always display the current scroll bar value..PPA signal can even be connected to another signal, i.e. \fImember\fR is a SIGNAL()..PP.nf.br class MyWidget : public QWidget.br {.br public:.br MyWidget();.br ....br signals:.br void aSignal();.br ....br private:.br ....br QPushButton *aButton;.br };.br.br MyWidget::MyWidget().br {.br aButton = new QPushButton( this );.br connect( aButton, SIGNAL(clicked()), SIGNAL(aSignal()) );.br }.fi.PPIn its constructor, MyWidget creates a private button and connects the clicked() signal to relay clicked() to the outside world. You can achieve the same effect by connecting the clicked() signal to a private slot and emitting aSignal() in this slot, but that takes a few lines of extra code and is not quite as clear, of course..PPA signal can be connected to many slots/signals. Many signals can be connected to one slot..PPIf a signal is connected to several slots, the slots are activated in arbitrary order when the signal is emitted..PPThe function returns TRUE if it successfully connects the signal to the slot. It will return FALSE when it cannot connect the signal to the slot..PPSee also disconnect()..PPExamples:.(lmovies/main.cpp hello/main.cpp iconview/main.cpp scrollview/scrollview.cpp i18n/main.cpp helpviewer/main.cpp showimg/main.cpp.)l.SH "bool QObject::connect ( const QObject * sender, const char * signal, const char * member ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPConnects \fIsignal\fR from the \fIsender\fR object to \fImember\fR in this object..PPEquivalent to: \fCQObject::connect(sender, signal, this, member)\fR..PPSee also disconnect()..PPExamples:.(lqwerty/main.cpp drawdemo/drawdemo.cpp mdi/main.cpp action/main.cpp forever/forever.cpp addressbook/main.cpp customlayout/main.cpp qmag/qmag.cpp menu/menu.cpp xform/xform.cpp popup/popup.cpp rot13/rot13.cpp grapher/grapher.cpp application/main.cpp.)l.SH "void QObject::connectNotify ( const char * signal ) \fC[virtual protected]\fR"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..PPSee also connect() and disconnectNotify()..PPReimplemented in QClipboard..SH "void QObject::destroyed () \fC[signal]\fR"This signal is emitted immediately before the object is destroyed..PPAll the objects's children are destroyed immediately after this signal is emitted..SH "bool QObject::disconnect ( const QObject * sender, const char * signal, const QObject * receiver, const char * member ) \fC[static]\fR"Disconnects \fIsignal\fR in object \fIsender\fR from \fImember\fR in object \fIreceiver.\fR.PPA signal-slot connection is removed when either of the objects involved are destroyed..PPdisconnect() is typically used in three ways, as the following examples show..IP 1Disconnect everything connected to an object's signals:.IP.nf.br disconnect( myObject, 0, 0, 0 );.fi.IPequivalent to the non-static overloaded function.IP.nf.br myObject->disconnect();.fi.IP 2Disconnect everything connected to a specific signal:.IP.nf.br disconnect( myObject, SIGNAL(mySignal()), 0, 0 );.fi.IPequivalent to the non-static overloaded function.IP.nf.br myObject->disconnect( SIGNAL(mySignal()) );.fi.IP 3Disconnect a specific receiver..IP.nf.br disconnect( myObject, 0, myReceiver, 0 );.fi.IPequivalent to the non-static overloaded function.IP.nf.br myObject->disconnect( myReceiver );.fi.IP.PP0 may be used as a wildcard, meaning "any signal", "any receiving object" or "any slot in the receiving object" respectively..PPThe \fIsender\fR may never be 0. (You cannot disconnect signals from more than one object.).PPIf \fIsignal\fR is 0, it disconnects \fIreceiver\fR and \fImember\fR from any signal. If not, only the specified signal is disconnected..PPIf \fIreceiver\fR is 0, it disconnects anything connected to \fIsignal.\fR If not, slots in objects other than \fIreceiver\fR are not disconnected..PPIf \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..PPSee also connect()..SH "bool QObject::disconnect ( const QObject * receiver, const char * member=0 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPDisconnects all signals in this object from \fImember\fR of \fIreceiver.\fR.PPA signal-slot connection is removed when either of the objects involved are destroyed..SH "bool QObject::disconnect ( const char * signal=0, const QObject * receiver=0, const char * member=0 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPDisconnects \fIsignal\fR from \fImember\fR of \fIreceiver.\fR.PPA signal-slot connection is removed when either of the objects involved are destroyed..SH "void QObject::disconnectNotify ( const char * signal ) \fC[virtual protected]\fR"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..PPSee also disconnect() and connectNotify()..SH "void QObject::dumpObjectInfo ()"Dumps information about signal connections etc. for this object to the debug output..PPThis function is useful for debugging. This function does nothing if the library has been compiled in release mode (i.e without debugging information)..SH "void QObject::dumpObjectTree ()"Dumps a tree of children to the debug output..PPThis function is useful for debugging. This function does nothing if the library has been compiled in release mode (i.e without debugging information)..SH "bool QObject::event ( QEvent * e ) \fC[virtual]\fR"This virtual function receives events to an object and should return TRUE if the event was recognized and processed..PPThe event() function can be reimplemented to customize the behavior of an object..PPSee also installEventFilter(), timerEvent(), QApplication::sendEvent(), QApplication::postEvent() and QWidget::event()..PPReimplemented in QSplitter, QWidget, QMainWindow, QToolBar, QTimer, QGroupBox, QMultiLineEdit, QLineEdit, QClipboard, QStatusBar and QSocketNotifier..SH "bool QObject::eventFilter ( QObject *, QEvent * ) \fC[virtual]\fR"Filters events if this object has been installed as an event filter for another object..PPThe reimplementation of this virtual function must return TRUE if the event should be stopped, or FALSE if the event should be dispatched normally..PP\fBWarning:\fR If you delete the receiver object in this 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 installEventFilter()..PPReimplemented in QFontDialog, QIconView, QWizard, QSGIStyle, QWorkspace, QListView, QSpinBox, QMenuBar, QFileDialog, QLayout, QAccel, QComboBox, QTable, QToolBar, QMotifPlusStyle, QMainWindow, QTabWidget and QScrollView..SH "bool QObject::highPriority () const"Returns TRUE if the object is a high priority object, or FALSE if it is a standard priority object..PPHigh priority objects are placed first in list of children, on the assumption that they will be referenced very often..SH "bool QObject::inherits ( const char * clname ) const"Returns TRUE if this object is an instance of a class that inherits \fIclname,\fR and \fIclname\fR inherits QObject..PP(A class is considered to inherit itself.).PPExample:.PP.nf.br QTimer *t = new QTimer; // QTimer inherits QObject.br t->inherits("QTimer"); // returns TRUE.br t->inherits("QObject"); // returns TRUE.br t->inherits("QButton"); // returns FALSE.br.br QScrollBar * s = new QScrollBar; // inherits QWidget and QRangeControl.br s->inherits( "QWidget" ); // returns TRUE.br s->inherits( "QRangeControl" ); // returns FALSE.fi.PPSee also isA() and metaObject()..SH "void QObject::initMetaObject () \fC[virtual protected]\fR"Initializes the meta object of this object. This method is automatically executed on demand..PPSee also metaObject()..SH "void QObject::insertChild ( QObject * obj ) \fC[virtual]\fR"Inserts an object \fIobj\fR into the list of child objects..PP\fBWarning:\fR This function cannot be used to make a widget a child widget of another. Child widgets can be created only by setting the parent widget in the constructor or by calling QWidget::reparent()..PPSee also removeChild() and QWidget::reparent()..SH "void QObject::installEventFilter ( const QObject * obj )"Installs an event filter \fIobj\fR for this object..PPAn 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 \fIobj\fR receives events via its eventFilter() function. The eventFilter() function must return TRUE if the event should be stopped, or FALSE if the event should be dispatched normally..PPIf multiple event filters are installed for a single object, the filter that was installed last is activated first..PPExample:.PP.nf.br #include <qwidget.h>.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 *o, 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -