📄 qobject.3qt
字号:
.br emit done();.br }.br }.fi.PPWhen an object has changed in some way that might be interesting for the outside world, it emits a signal to tell whoever is listening. All slots that are connected to this signal will be activated (called). It is even possible to connect a signal directly to another signal. (This will emit the second signal immediately whenever the first is emitted.).PPThere is no limitation on how many slots that can be connected to a signal. The slots will be activated in the order they were connected to the signal..PPNotice that the \fCQ_OBJECT\fR macro is mandatory for any object that implement signals or slots. You also need to run the moc program (Meta Object Compiler) on the source file..PPThe signal/slot mechanism allows objects to easily reused, because the object that emits a signal does not need to know what the signals are connected to..PPAll Qt widgets inherit QObject and use signals and slots. A QScrollBar, for example, emits valueChanged() whenever the scroll bar value changes..PPMeta objects are useful for doing more than connecting signals to slots. They also allow the programmer to obtain information about the class to which an object is instantiated from (see isA() and inherits()) or to produce a list of child objects that inherit a particular class (see queryList())..SH MEMBER FUNCTION DOCUMENTATION.SH "QObject::QObject ( QObject * parent=0, const char * name=0 )"Constructs an object with the parent object \fIparent\fR and a \fIname.\fR.PPThe 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 inside it..PPThe destructor of a parent object destroys all child objects..PPSetting \fIparent\fR to 0 constructs an object with no parent. If the object is a widget, it will become a top-level window..PPThe object name is a text that can be used to identify this QObject. It 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: parent(), name() and queryList()..SH "QObject::~QObject () \fC[virtual]\fR"Destroys the object and all its children objects..PPAll signals to and from the object are automatically disconnected..PP\fBWarning:\fR \fIAll\fR child objects are deleted. If any of these objects are on the stack or global, your program will sooner or later crash. We do not recommend holding pointers to child objects from outside the parent. If you still do, the QObject::destroyed() signal gives you an opportunity to detect when an object is destroyed..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 "void QObject::activate_signal ( const char * signal, const char * ) \fC[protected]\fR"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QObject::activate_signal ( const char * signal, int ) \fC[protected]\fR"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QObject::activate_signal ( const char * signal, long ) \fC[protected]\fR"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QObject::activate_signal ( const char * signal, short ) \fC[protected]\fR"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "void QObject::badSuperclassWarning ( const char * className, const char * superclassName ) \fC[static protected]\fR"Internal function, called from initMetaObject(). Used to emit a warning when a class containing the macro Q_OBJECT inherits from a class that does not contain it..SH "void QObject::blockSignals ( bool block )"Blocks signals if \fIblock\fR is TRUE, or unblocks signals if \fIblock\fR is FALSE..PPEmitted signals disappear into hyperspace if signals are blocked..SH "bool QObject::checkConnectArgs ( const char * signal, const QObject * receiver, const char * member ) \fC[virtual protected]\fR"Returns TRUE if the \fIsignal\fR and the \fImember\fR arguments are compatible, otherwise FALSE..PP\fBWarning:\fR We recommend that you do not reimplement this function but use the default implementation..SH "QObject* QObject::child ( const char * name, const char * type = 0 )"Returns the pointer to a child widget with the required name and type or 0 if no child matches. This function works recursive. That means it traverses the entire object tree to find the child. That in turn means that names have to be unique with regard to their toplevel window..PPIf multiple widgets with the same name and type are found then it is undefined which one of them is returned..PPIf \fItype\fR is set to 0 then the only criterion is the objects name..PPThis function is useful if you need a widget of a dialog that was created from a ressource file..SH "void QObject::childEvent ( QChildEvent * ) \fC[virtual protected]\fR"This event handler can be reimplemented in a subclass to receive child events..PPChild events are sent to objects when children are inserted or removed..PPSee also: event() and QChildEvent..PPReimplemented in QMainWindow, QWidgetStack and QSplitter..SH "const QObjectList * QObject::children () const"Returns a list of child objects, or 0 if this object has no children..PPThe QObjectList class is defined in the qobjcoll.h header file..PPThe latest child added is the first object in the list and the first child is added is the last object in the list..PPNote that the list order might change when widget children are raised or lowered. A widget that is raised becomes the last object in the list. A widget that is lowered becomes the first object in the list..PPSee also: 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..PPSee also: disconnect()..PPExamples:.(lshowimg/main.cpp grapher/grapher.cpp xform/xform.cpp application/main.cpp qiconview/main.cpp drawdemo/drawdemo.cpp popup/popup.cpp menu/menu.cpp qmag/qmag.cpp qwerty/main.cpp forever/forever.cpp rot13/rot13.cpp scrollview/scrollview.cpp addressbook/main.cpp movies/main.cpp hello/main.cpp qbrowser/main.cpp customlayout/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()..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 );.fi.IP 2Disconnect everything connected to a signal:.IP.nf.br disconnect( myObject, SIGNAL(mySignal()) );.fi.IP 3Disconnect a specific receiver..IP.nf.br disconnect( myObject, 0, myReceiver, 0 );.fi.IP.PP0 may be used as a wildcard in three of the four arguments, meaning "any signal", "any receiving object" or "any slot in the receiving object" respectively..PPThe \fIsender\fR has no default and 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..SH "void QObject::dumpObjectTree ()"Dumps a tree of children to the debug output..PPThis function is useful for debugging..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, QToolBar, QClipboard, QSocketNotifier, QTimer, QMainWindow and QWidget..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..PPSee also: installEventFilter()..PPReimplemented in QScrollView, QAccel, QToolBar, QMainWindow, QTabWidget, QFontDialog, QListView, QComboBox, QFileDialog, QSpinBox, QLayout, QMenuBar and QWizard..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 from the QObject constructor..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 object 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 object receives events via the 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 will be activated first..PPExample:.PP.nf.br #include <qwidget.h>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -