|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
public class QObject
The QObject
class is the base class of all Qt objects. QObject
is the heart of the Qt object model. The central feature in this model is a very powerful mechanism for seamless object communication called signals and slots. You can connect a signal to a slot with connect() and destroy the connection with disconnect(). To avoid never ending notification loops you can temporarily block signals with blockSignals()
. The protected functions connectNotify() and disconnectNotify() make it possible to track connections.
QObjects organize themselves in object trees. When you create a QObject
with another object as parent, the object will automatically add itself to the parent's children()
list. The parent takes ownership of the object i.e. it will automatically delete its children in its destructor. You can look for an object by name and optionally type using findChild()
or findChildren()
.
Every object has an objectName()
and its class name can be found via the corresponding metaObject() (see QMetaObject::className()). You can determine whether the object's class inherits another class in the QObject
inheritance hierarchy by using the inherits() function.
When an object is deleted, it emits a destroyed() signal. You can catch this signal to avoid dangling references to QObjects.
QObjects can receive events through event()
and filter the events of other objects. See installEventFilter()
and eventFilter()
for details. A convenience handler, childEvent()
, can be reimplemented to catch child events.
Events are delivered in the thread in which the object was created; see Thread Support in Qt and thread()
for details. Note that event processing is not done at all for QObjects with no thread affinity (thread()
returns zero). Use the moveToThread()
function to change the thread affinity for an object and its children (the object cannot be moved if it has a parent).
Last but not least, QObject
provides the basic timer support in Qt; see QTimer
for high-level support for timers.
Notice that the Q_OBJECT macro is mandatory for any object that implements signals, slots or properties. You also need to run the Meta Object Compiler on the source file. We strongly recommend the use of this macro in all subclasses of QObject
regardless of whether or not they actually use signals, slots and properties, since failure to do so may lead certain functions to exhibit strange behavior.
All Qt widgets inherit QObject
. The convenience function isWidgetType()
returns whether an object is actually a widget. It is much faster than qobject_cast<QWidget
*>(obj) or obj->inherits("QWidget
").
Some QObject
functions, e.g. children()
, return a QObjectList. QObjectList is a typedef for QList<QObject
*>.No copy constructor or assignment operator
QObject
has neither a copy constructor nor an assignment operator. This is by design. Actually, they are declared, but in a private section with the macro Q_DISABLE_COPY(). In fact, all Qt classes derived from QObject
(direct or indirect) use this macro to declare their copy constructor and assignment operator to be private. The reasoning is found in the discussion on Identity vs Value on the Qt Object Model page.
The main consequence is that you should use pointers to QObject
(or to your QObject
subclass) where you might otherwise be tempted to use your QObject
subclass as a value. For example, without a copy constructor, you can't use a subclass of QObject
as the value to be stored in one of the container classes. You must store pointers.Auto-Connection
Qt's meta-object system provides a mechanism to automatically connect signals and slots between QObject
subclasses and their children. As long as objects are defined with suitable object names, and slots follow a simple naming convention, this connection can be performed at run-time by the QMetaObject::connectSlotsByName() function.
uic generates code that invokes this function to enable auto-connection to be performed between widgets on forms created with Qt Designer. More information about using auto-connection with Qt Designer is given in the Using a Component in Your Application section of the Qt Designer manual.Dynamic Properties
From Qt 4.2, dynamic properties can be added to and removed from QObject
instances at run-time. Dynamic properties do not need to be declared at compile-time, yet they provide the same advantages as static properties and are manipulated using the same API - using property()
to read them and setProperty()
to write them.
From Qt 4.3, dynamic properties are supported by Qt Designer, and both standard Qt widgets and user-created forms can be given dynamic properties.
{Object Trees and Object Ownership}
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QObject()
|
|
QObject(QObject parent)
|
Method Summary | |
---|---|
protected void |
childEvent(QChildEvent arg__1)
|
java.util.List |
children()
|
void |
connectSlotsByName()
Searches recursively for all child objects of the given object, and connects matching signals from them to slots of object that follow the following form. |
protected void |
customEvent(QEvent arg__1)
|
void |
disposeLater()
|
void |
dumpObjectInfo()
|
void |
dumpObjectTree()
|
java.util.List |
dynamicPropertyNames()
|
boolean |
event(QEvent arg__1)
|
boolean |
eventFilter(QObject arg__1,
QEvent arg__2)
|
QObject |
findChild()
Returns a child of this object, or 0 if there is no such object. |
QObject |
findChild(java.lang.Class cl)
This functions searches for descendant(s) of this QObject. |
QObject |
findChild(java.lang.Class cl,
java.lang.String name)
This functions searches for descendant(s) of this QObject. |
java.util.List |
findChildren()
Returns all children of this QObject, or an empty list if it has no children. |
java.util.List |
findChildren(java.lang.Class cl)
This functions searches for descendant(s) of this QObject. |
java.util.List |
findChildren(java.lang.Class cl,
QRegExp name)
This functions searches for descendant(s) of this QObject. |
java.util.List |
findChildren(java.lang.Class cl,
java.lang.String name)
This functions searches for descendant(s) of this QObject. |
int |
indexOfProperty(java.lang.String name)
Finds property name and returns its index; otherwise returns -1. |
void |
installEventFilter(QObject arg__1)
|
boolean |
isWidgetType()
|
void |
killTimer(int id)
|
void |
moveToThread(java.lang.Thread thread)
|
java.lang.String |
objectName()
|
QObject |
parent()
|
java.util.List |
properties()
This functions searches for descendant(s) of this QObject. |
java.lang.Object |
property(java.lang.String name)
Returns the value of the object's name property. |
void |
removeEventFilter(QObject arg__1)
|
void |
setObjectName(java.lang.String name)
|
void |
setParent(QObject arg__1)
|
void |
setProperty(java.lang.String name,
java.lang.Object value)
Sets the value of the object's name property to value. |
int |
startTimer(int interval)
|
protected void |
timerEvent(QTimerEvent arg__1)
|
java.lang.String |
toString()
|
QtProperty |
userProperty()
Returns the property that has the USER flag set to true. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QObject()
public QObject(QObject parent)
Method Detail |
---|
public final java.util.List children()
public final void disposeLater()
public final void dumpObjectInfo()
public final void dumpObjectTree()
public final java.util.List dynamicPropertyNames()
public final void installEventFilter(QObject arg__1)
public final boolean isWidgetType()
public final void killTimer(int id)
public final void moveToThread(java.lang.Thread thread)
public final java.lang.String objectName()
public final QObject parent()
public final void removeEventFilter(QObject arg__1)
public final void setObjectName(java.lang.String name)
public final void setParent(QObject arg__1)
public final int startTimer(int interval)
protected void childEvent(QChildEvent arg__1)
protected void customEvent(QEvent arg__1)
public boolean event(QEvent arg__1)
public boolean eventFilter(QObject arg__1, QEvent arg__2)
protected void timerEvent(QTimerEvent arg__1)
public final java.util.List findChildren()
public final java.util.List findChildren(java.lang.Class cl)
public final java.util.List findChildren(java.lang.Class cl, java.lang.String name)
public final java.util.List findChildren(java.lang.Class cl, QRegExp name)
public final QObject findChild()
If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned. In that case, findChildren() should be used.
public final QObject findChild(java.lang.Class cl)
public final QObject findChild(java.lang.Class cl, java.lang.String name)
public final void setProperty(java.lang.String name, java.lang.Object value)
If the property is defined in the class using Q_PROPERTY then true is returned on success and false otherwise. If the property is not defined using Q_PROPERTY, and therefore not listed in the meta-object, it is added as a dynamic property and false is returned.
Information about all available properties is provided through the metaObject() and dynamicPropertyNames().
Dynamic properties can be queried again using property() and can be removed by setting the property value to an invalid QVariant. Changing the value of a dynamic property causes a QDynamicPropertyChangeEvent to be sent to the object.
Note: Dynamic properties starting with "_q_" are reserved for internal purposes.
public final java.lang.Object property(java.lang.String name)
If no such property exists, the returned object is invalid.
Information about all available properties is provided through the metaObject() and dynamicPropertyNames().
public final QtProperty userProperty()
public final java.util.List properties()
public final int indexOfProperty(java.lang.String name)
public final void connectSlotsByName()
void on_
Let's assume our object has a child object of type QPushButton with the object name button1. The slot to catch the button's clicked signal would be:
void on_button1_clicked()
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |