Qyoto
4.0.5
Qyoto is a C# language binding for Qt
|
The QObject class is the base class of all Qt objects. More...
Inherits QtCore.Qt, ISmokeObject, and IDisposable.
Inherited by QtCore.QAbstractAnimation, QtCore.QAbstractEventDispatcher, QtCore.QAbstractItemModel, QtCore.QAbstractState, QtCore.QAbstractTransition, QtCore.QCoreApplication, QtCore.QEventLoop, QtCore.QFileSystemWatcher, QtCore.QFutureWatcherBase, QtCore.QIODevice, QtCore.QLibrary, QtCore.QMimeData, QtCore.QObjectCleanupHandler, QtCore.QPluginLoader, QtCore.QSettings, QtCore.QSharedMemory, QtCore.QSignalMapper, QtCore.QSocketNotifier, QtCore.QTextCodecPlugin, QtCore.QTimeLine, QtCore.QTimer, QtCore.QTranslator, QtGui.QAbstractItemDelegate, QtGui.QAbstractTextDocumentLayout, QtGui.QAction, QtGui.QActionGroup, QtGui.QButtonGroup, QtGui.QClipboard, QtGui.QCompleter, QtGui.QDataWidgetMapper, QtGui.QDrag, QtGui.QGesture, QtGui.QGraphicsAnchor, QtGui.QGraphicsEffect, QtGui.QGraphicsItemAnimation, QtGui.QGraphicsObject, QtGui.QGraphicsScene, QtGui.QGraphicsTransform, QtGui.QIconEnginePlugin, QtGui.QIconEnginePluginV2, QtGui.QImageIOPlugin, QtGui.QInputContext, QtGui.QInputContextPlugin, QtGui.QItemSelectionModel, QtGui.QLayout, QtGui.QMovie, QtGui.QPictureFormatPlugin, QtGui.QSessionManager, QtGui.QShortcut, QtGui.QSound, QtGui.QStyle, QtGui.QStylePlugin, QtGui.QSystemTrayIcon, QtGui.QTextDocument, QtGui.QTextObject, QtGui.QUndoGroup, QtGui.QUndoStack, QtGui.QValidator, QtGui.QWidget, QtNetwork.QAbstractNetworkCache, QtNetwork.QFtp, QtNetwork.QHttp, QtNetwork.QHttpMultiPart, QtNetwork.QLocalServer, QtNetwork.QNetworkAccessManager, QtNetwork.QNetworkConfigurationManager, QtNetwork.QNetworkCookieJar, QtNetwork.QNetworkSession, QtNetwork.QTcpServer, QtOpenGL.QGLShader, QtOpenGL.QGLShaderProgram, QtScript.QScriptEngine, QtScript.QScriptExtensionPlugin, QtSql.QSqlDriver, QtSql.QSqlDriverPlugin, QtSvg.QSvgRenderer, QtUiTools.QUiLoader, QtWebKit.QWebFrame, QtWebKit.QWebHistoryInterface, QtWebKit.QWebPage, QtWebKit.QWebPluginFactory, QtXmlPatterns.QAbstractMessageHandler, and QtXmlPatterns.QAbstractUriResolver.
Public Member Functions | |
QObject (QObject parent=null) | |
| |
virtual void | CreateProxy () |
new bool | BlockSignals (bool b) |
| |
new System.Collections.Generic.List < QObject > | Children () |
| |
new bool | Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection) |
| |
new void | DeleteLater () |
| |
new bool | Disconnect (QObject receiver, string member=null) |
| |
new bool | Disconnect (string signal=null, QObject receiver=null, string member=null) |
| |
new void | DumpObjectInfo () |
| |
new void | DumpObjectTree () |
| |
new System.Collections.Generic.List < QByteArray > | DynamicPropertyNames () |
| |
virtual bool | OnEvent (QEvent arg1) |
| |
virtual bool | EventFilter (QObject arg1, QEvent arg2) |
| |
new bool | Inherits (string classname) |
| |
new void | InstallEventFilter (QObject arg1) |
| |
new bool | IsWidgetType () |
| |
new void | KillTimer (int id) |
| |
new object | Property (string name) |
| |
new void | RemoveEventFilter (QObject arg1) |
| |
new bool | SetProperty (string name, object value) |
| |
new void | SetUserData (uint id, QObjectUserData data) |
new bool | SignalsBlocked () |
| |
new int | StartTimer (int interval) |
| |
new QObjectUserData | UserData (uint id) |
new void | Dispose () |
Public Member Functions inherited from QtCore.Qt | |
delegate QTextStream | FuncQTextStreamQTextStream (QTextStream qTextStream) |
delegate string | FuncStringQByteArray (QByteArray qByteArray) |
delegate QByteArray | FuncQByteArrayString (string @string) |
delegate void | ActionQtMsgTypeString (QtMsgType qtMsgType, string @string) |
delegate QObject | FuncQObject () |
Static Public Member Functions | |
static bool | Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection) |
| |
static bool | Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection) |
| |
static bool | Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member) |
| |
static bool | Disconnect (QObject sender, string signal, QObject receiver, string member) |
| |
static uint | RegisterUserData () |
static string | Tr (string s, string c=null) |
| |
static string | Tr (string s, string c, int n) |
| |
static string | TrUtf8 (string s, string c=null) |
| |
static string | TrUtf8 (string s, string c, int n) |
| |
Static Public Member Functions inherited from QtCore.Qt | |
static QDataStream | Write (QDataStream s, object p) |
static QDataStream | Write (QDataStream arg1, QSizeF arg2) |
static QTextStream | Write (QTextStream s, Qt.FuncQTextStreamQTextStream f) |
static QDataStream | Write (QDataStream arg1, QPoint arg2) |
static QDataStream | Write (QDataStream arg1, QLineF arg2) |
static QDataStream | Write (QDataStream arg1, QPointF arg2) |
static QDataStream | Write (QDataStream arg1, QChar arg2) |
static QDataStream | Write (QDataStream arg1, QByteArray arg2) |
static QDataStream | Write (QDataStream arg1, QEasingCurve arg2) |
static QDataStream | Write (QDataStream arg1, QRectF arg2) |
static QDataStream | Write (QDataStream arg1, QDateTime arg2) |
static QDataStream | Write (QDataStream arg1, QUrl arg2) |
static QDataStream | Write (QDataStream arg1, QTime arg2) |
static QDataStream | Write (QDataStream arg1, QLocale arg2) |
static QDataStream | Write (QDataStream arg1, QBitArray arg2) |
static QDataStream | Write (QDataStream arg1, QUuid arg2) |
static QDataStream | Write (QDataStream arg1, QLine arg2) |
static QDataStream | Write (QDataStream arg1, QDate arg2) |
static QDataStream | Write (QDataStream @out, QRegExp regExp) |
static QDataStream | Write (QDataStream arg1, QRect arg2) |
static QDataStream | Write (QDataStream arg1, QSize arg2) |
static QDataStream | Write (QDataStream s, QVariant.Type p) |
static QDataStream | Write (QDataStream arg1, string arg2) |
static QDataStream | Write (QDataStream @out, System.Collections.Generic.List< string > list) |
static QDataStream | Read (QDataStream arg1, QChar arg2) |
static QDataStream | Read (QDataStream arg1, QLocale arg2) |
static QDataStream | Read (QDataStream arg1, QRect arg2) |
static QDataStream | Read (QDataStream arg1, QEasingCurve arg2) |
static QDataStream | Read (QDataStream arg1, QDate arg2) |
static QDataStream | Read (QDataStream arg1, QUrl arg2) |
static QDataStream | Read (QDataStream arg1, QUuid arg2) |
static QTextStream | Read (QTextStream s, Qt.FuncQTextStreamQTextStream f) |
static QDataStream | Read (QDataStream arg1, QLineF arg2) |
static QDataStream | Read (QDataStream arg1, QRectF arg2) |
static QDataStream | Read (QDataStream arg1, QPointF arg2) |
static QDataStream | Read (QDataStream arg1, QLine arg2) |
static QDataStream | Read (QDataStream arg1, QBitArray arg2) |
static QDataStream | Read (QDataStream arg1, QSize arg2) |
static QDataStream | Read (QDataStream arg1, QDateTime arg2) |
static QDataStream | Read (QDataStream arg1, QTime arg2) |
static QDataStream | Read (QDataStream arg1, QPoint arg2) |
static QDataStream | Read (QDataStream @in, QRegExp regExp) |
static QDataStream | Read (QDataStream s, object p) |
static QDataStream | Read (QDataStream arg1, QByteArray arg2) |
static QDataStream | Read (QDataStream arg1, QSizeF arg2) |
static QDataStream | Read (QDataStream arg1, string arg2) |
static QDataStream | Read (QDataStream s, QVariant.Type p) |
static QDataStream | Read (QDataStream @in, System.Collections.Generic.List< string > list) |
static double | qAcos (double v) |
static void | qAddPostRoutine (System.Action arg1) |
static string | qAppName () |
static double | qAsin (double v) |
static double | qAtan (double v) |
static double | qAtan2 (double x, double y) |
static void | qBadAlloc () |
static int | qCeil (double v) |
static ushort | qChecksum (string s, uint len) |
static QByteArray | qCompress (QByteArray data) |
static QByteArray | qCompress (QByteArray data, int compressionLevel=-1) |
static QByteArray | qCompress (Pointer< byte > data, int nbytes) |
static QByteArray | qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1) |
static double | qCos (double v) |
static double | qExp (double v) |
static double | qFabs (double v) |
static double | qFastCos (double x) |
static double | qFastSin (double x) |
static string | qFlagLocation (string method) |
static int | qFloor (double v) |
static bool | qFuzzyCompare (double p1, double p2) |
static bool | qFuzzyCompare (float p1, float p2) |
static bool | qFuzzyIsNull (double d) |
static bool | qFuzzyIsNull (float f) |
static uint | qHash (QBitArray key) |
static uint | qHash (QChar key) |
static uint | qHash (QStringRef key) |
static uint | qHash (QUrl url) |
static uint | qHash (QPersistentModelIndex index) |
static uint | qHash (QByteArray key) |
static uint | qHash (QModelIndex index) |
static uint | qHash (uint key) |
static uint | qHash (sbyte key) |
static uint | qHash (byte key) |
static uint | qHash (short key) |
static uint | qHash (NativeLong key) |
static uint | qHash (ushort key) |
static uint | qHash (long key) |
static uint | qHash (ulong key) |
static uint | qHash (int key) |
static uint | qHash (string key) |
static uint | qHash (NativeULong key) |
static double | qInf () |
static Qt.ActionQtMsgTypeString | qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1) |
static int | qIntCast (float f) |
static int | qIntCast (double f) |
static bool | qIsFinite (double d) |
static bool | qIsFinite (float f) |
static bool | qIsInf (float f) |
static bool | qIsInf (double d) |
static bool | qIsNaN (float f) |
static bool | qIsNaN (double d) |
static bool | qIsNull (float f) |
static bool | qIsNull (double d) |
static double | qLn (double v) |
static double | qPow (double x, double y) |
static double | qQNaN () |
static void | qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function) |
static void | qRemovePostRoutine (System.Action arg1) |
static int | qRound (double d) |
static long | qRound64 (double d) |
static double | qSNaN () |
static bool | qSharedBuild () |
static double | qSin (double v) |
static double | qSqrt (double v) |
static bool | qStringComparisonHelper (QStringRef s1, string s2) |
static double | qTan (double v) |
static QByteArray | qUncompress (QByteArray data) |
static QByteArray | qUncompress (Pointer< byte > data, int nbytes) |
static string | qVersion () |
static void | Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size) |
static QByteArray | Qgetenv (string varName) |
static bool | Qputenv (string varName, QByteArray value) |
static int | Qrand () |
static void | Qsrand (uint seed) |
static int | Qstrcmp (QByteArray str1, QByteArray str2) |
static int | Qstrcmp (QByteArray str1, string str2) |
static int | Qstrcmp (string str1, QByteArray str2) |
static int | Qstrcmp (string str1, string str2) |
static Pointer< sbyte > | Qstrcpy (Pointer< sbyte > dst, string src) |
static Pointer< sbyte > | Qstrdup (string arg1) |
static int | Qstricmp (string arg1, string arg2) |
static uint | Qstrlen (string str) |
static int | Qstrncmp (string str1, string str2, uint len) |
static Pointer< sbyte > | Qstrncpy (Pointer< sbyte > dst, string src, uint len) |
static int | Qstrnicmp (string arg1, string arg2, uint len) |
static uint | Qstrnlen (string str, uint maxlen) |
static string | QtTrId (string id, int n=-1) |
Protected Member Functions | |
QObject (System.Type dummy) | |
virtual void | OnChildEvent (QChildEvent arg1) |
| |
virtual void | ConnectNotify (string signal) |
| |
virtual void | OnCustomEvent (QEvent arg1) |
| |
new void | OnDestroyed (QObject arg1=null) |
| |
virtual void | DisconnectNotify (string signal) |
| |
new int | Receivers (string signal) |
| |
new QObject | Sender () |
| |
new int | SenderSignalIndex () |
| |
virtual void | OnTimerEvent (QTimerEvent arg1) |
| |
Protected Attributes | |
object | Q_EMIT = null |
SmokeInvocation | interceptor |
readonly List< QEventHandler > | eventFilters = new List<QEventHandler>() |
Properties | |
virtual EventHandler < QEventArgs< QChildEvent > > | ChildEvent |
| |
virtual EventHandler < QEventArgs< QEvent > > | CustomEvent |
| |
virtual EventHandler < QEventArgs< QEvent > > | Event |
| |
virtual EventHandler < QEventArgs< QTimerEvent > > | TimerEvent |
| |
Slot< QObject > | DestroyedQObject |
Slot | Destroyed |
| |
new QObject | Parent [get, set] |
| |
virtual System.IntPtr | SmokeObject [get, set] |
new string | ObjectName [get, set] |
| |
static new QMetaObject | StaticMetaObject [get] |
| |
static new QMetaObject | StaticQtMetaObject [get] |
new IQObjectSignals | Emit [get] |
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 Designer UI File 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.
Internationalization (i18n)
All QObject subclasses support Qt's translation features, making it possible to translate an application's user interface into different languages.
To make user-visible text translatable, it must be wrapped in calls to the tr() function. This is explained in detail in the Writing Source Code for Translation document.
See also QMetaObject, QPointer, QObjectCleanupHandler, Q_DISABLE_COPY(), and Object Trees & Ownership.
|
protected |
QtCore.QObject.QObject | ( | QObject | parent = null | ) |
Constructs an object with parent object parent.
The 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 it contains.
The destructor of a parent object destroys all child objects.
Setting parent to 0 constructs an object with no parent. If the object is a widget, it will become a top-level window.
See also parent(), findChild(), and findChildren().
new bool QtCore.QObject.BlockSignals | ( | bool | b | ) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). If block is false, no such blocking will occur.
The return value is the previous value of signalsBlocked().
Note that the destroyed() signal will be emitted even if the signals for this object have been blocked.
See also signalsBlocked().
new System.Collections.Generic.List<QObject> QtCore.QObject.Children | ( | ) |
Returns a list of child objects. The QObjectList class is defined in the <QObject> header file as the following:
typedef QList<QObject*> QObjectList;
The first child added is the first object in the list and the last child added is the last object in the list, i.e. new children are appended at the end.
Note 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.
See also findChild(), findChildren(), parent(), and setParent().
|
static |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. Returns true if the connection succeeds; otherwise returns false.
You must use the SIGNAL() and SLOT() macros when specifying the signal and the method, for example:
QLabel *label = new QLabel;
QScrollBar *scrollBar = new QScrollBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return false:
// WRONG
QObject::connect(scrollBar, SIGNAL(valueChanged(int value)),
label, SLOT(setNum(int value)));
A signal can also be connected to another signal:
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget();
signals:
void buttonClicked();
private:
QPushButton *myButton;
};
MyWidget::MyWidget()
{
myButton = new QPushButton(this);
connect(myButton, SIGNAL(clicked()),
this, SIGNAL(buttonClicked()));
}
In this example, the MyWidget constructor relays a signal from a private member variable, and makes it available under a name that relates to MyWidget.
A signal can be connected to many slots and signals. Many signals can be connected to one slot.
If a signal is connected to several slots, the slots are activated in the same order as the order the connection was made, when the signal is emitted.
The function returns true if it successfully connects the signal to the slot. It will return false if it cannot create the connection, for example, if QObject is unable to verify the existence of either signal or method, or if their signatures aren't compatible.
By default, a signal is emitted for every connection you make; two signals are emitted for duplicate connections. You can break all of these connections with a single disconnect() call. If you pass the Qt::UniqueConnection type, the connection will only be made if it is not a duplicate. If there is already a duplicate (exact same signal to the exact same slot on the same objects), the connection will fail and connect will return false.
The optional type parameter describes the type of connection to establish. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time. If the signal is queued, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message
QObject::connect: Cannot queue arguments of type 'MyType'
(Make sure 'MyType' is registered using qRegisterMetaType().)
call qRegisterMetaType() to register the data type before you establish the connection.
Note: This function is thread-safe.
See also disconnect(), sender(), qRegisterMetaType(), and Q_DECLARE_METATYPE().
|
static |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. Returns true if the connection succeeds; otherwise returns false.
You must use the SIGNAL() and SLOT() macros when specifying the signal and the method, for example:
QLabel *label = new QLabel;
QScrollBar *scrollBar = new QScrollBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return false:
// WRONG
QObject::connect(scrollBar, SIGNAL(valueChanged(int value)),
label, SLOT(setNum(int value)));
A signal can also be connected to another signal:
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget();
signals:
void buttonClicked();
private:
QPushButton *myButton;
};
MyWidget::MyWidget()
{
myButton = new QPushButton(this);
connect(myButton, SIGNAL(clicked()),
this, SIGNAL(buttonClicked()));
}
In this example, the MyWidget constructor relays a signal from a private member variable, and makes it available under a name that relates to MyWidget.
A signal can be connected to many slots and signals. Many signals can be connected to one slot.
If a signal is connected to several slots, the slots are activated in the same order as the order the connection was made, when the signal is emitted.
The function returns true if it successfully connects the signal to the slot. It will return false if it cannot create the connection, for example, if QObject is unable to verify the existence of either signal or method, or if their signatures aren't compatible.
By default, a signal is emitted for every connection you make; two signals are emitted for duplicate connections. You can break all of these connections with a single disconnect() call. If you pass the Qt::UniqueConnection type, the connection will only be made if it is not a duplicate. If there is already a duplicate (exact same signal to the exact same slot on the same objects), the connection will fail and connect will return false.
The optional type parameter describes the type of connection to establish. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time. If the signal is queued, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message
QObject::connect: Cannot queue arguments of type 'MyType'
(Make sure 'MyType' is registered using qRegisterMetaType().)
call qRegisterMetaType() to register the data type before you establish the connection.
Note: This function is thread-safe.
See also disconnect(), sender(), qRegisterMetaType(), and Q_DECLARE_METATYPE().
new bool QtCore.QObject.Connect | ( | QObject | sender, |
string | signal, | ||
string | member, | ||
Qt.ConnectionType | type = Qt.ConnectionType.AutoConnection |
||
) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. Returns true if the connection succeeds; otherwise returns false.
You must use the SIGNAL() and SLOT() macros when specifying the signal and the method, for example:
QLabel *label = new QLabel;
QScrollBar *scrollBar = new QScrollBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not contain any variable names, only the type. E.g. the following would not work and return false:
// WRONG
QObject::connect(scrollBar, SIGNAL(valueChanged(int value)),
label, SLOT(setNum(int value)));
A signal can also be connected to another signal:
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget();
signals:
void buttonClicked();
private:
QPushButton *myButton;
};
MyWidget::MyWidget()
{
myButton = new QPushButton(this);
connect(myButton, SIGNAL(clicked()),
this, SIGNAL(buttonClicked()));
}
In this example, the MyWidget constructor relays a signal from a private member variable, and makes it available under a name that relates to MyWidget.
A signal can be connected to many slots and signals. Many signals can be connected to one slot.
If a signal is connected to several slots, the slots are activated in the same order as the order the connection was made, when the signal is emitted.
The function returns true if it successfully connects the signal to the slot. It will return false if it cannot create the connection, for example, if QObject is unable to verify the existence of either signal or method, or if their signatures aren't compatible.
By default, a signal is emitted for every connection you make; two signals are emitted for duplicate connections. You can break all of these connections with a single disconnect() call. If you pass the Qt::UniqueConnection type, the connection will only be made if it is not a duplicate. If there is already a duplicate (exact same signal to the exact same slot on the same objects), the connection will fail and connect will return false.
The optional type parameter describes the type of connection to establish. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time. If the signal is queued, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message
QObject::connect: Cannot queue arguments of type 'MyType'
(Make sure 'MyType' is registered using qRegisterMetaType().)
call qRegisterMetaType() to register the data type before you establish the connection.
Note: This function is thread-safe.
See also disconnect(), sender(), qRegisterMetaType(), and Q_DECLARE_METATYPE().
|
protectedvirtual |
This virtual function is called when something has been connected to signal in this object.
If you want to compare signal with a specific signal, use QLatin1String and the SIGNAL() macro as follows:
if (QLatin1String(signal) == SIGNAL(valueChanged(int))) {
// signal is valueChanged(int)
}
If the signal contains multiple parameters or parameters that contain spaces, call QMetaObject::normalizedSignature() on the result of the SIGNAL() macro.
Warning: 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.
See also connect() and disconnectNotify().
Reimplemented in QtCore.QFutureWatcherBase, QtGui.QClipboard, QtNetwork.QNetworkSession, and QtCore.QBuffer.
|
virtual |
Reimplemented in QtGui.QWorkspace, QtGui.QWizardPage, QtGui.QWizard, QtGui.QWidgetAction, QtGui.QWidget, QtGui.QValidator, QtGui.QVBoxLayout, QtGui.QUndoView, QtGui.QUndoStack, QtGui.QUndoGroup, QtGui.QTreeWidget, QtGui.QTreeView, QtGui.QToolButton, QtGui.QToolBox, QtGui.QToolBar, QtGui.QTimeEdit, QtGui.QTextTable, QtGui.QTextObject, QtGui.QTextList, QtGui.QTextFrame, QtGui.QTextEdit, QtGui.QTextDocument, QtGui.QTextBrowser, QtGui.QTextBlockGroup, QtGui.QTapGesture, QtGui.QTapAndHoldGesture, QtGui.QTableWidget, QtGui.QTableView, QtGui.QTabWidget, QtGui.QTabBar, QtGui.QSystemTrayIcon, QtGui.QSwipeGesture, QtGui.QStyledItemDelegate, QtGui.QStylePlugin, QtGui.QStyle, QtGui.QStringListModel, QtGui.QStatusBar, QtGui.QStandardItemModel, QtGui.QStackedWidget, QtGui.QStackedLayout, QtGui.QSplitterHandle, QtGui.QSplitter, QtGui.QSplashScreen, QtGui.QSpinBox, QtGui.QSound, QtGui.QSortFilterProxyModel, QtGui.QSlider, QtGui.QSizeGrip, QtGui.QShortcut, QtGui.QSessionManager, QtGui.QScrollBar, QtGui.QScrollArea, QtGui.QRubberBand, QtGui.QRegExpValidator, QtGui.QRadioButton, QtGui.QPushButton, QtGui.QProxyStyle, QtGui.QProxyModel, QtGui.QProgressDialog, QtGui.QProgressBar, QtGui.QPrintPreviewWidget, QtGui.QPrintPreviewDialog, QtGui.QPrintDialog, QtGui.QPlainTextEdit, QtGui.QPlainTextDocumentLayout, QtGui.QPinchGesture, QtGui.QPictureFormatPlugin, QtGui.QPanGesture, QtGui.QPageSetupDialog, QtGui.QMovie, QtGui.QMouseEventTransition, QtGui.QMessageBox, QtGui.QMenuBar, QtGui.QMenu, QtGui.QMdiSubWindow, QtGui.QMdiArea, QtGui.QMainWindow, QtGui.QListWidget, QtGui.QListView, QtGui.QLineEdit, QtGui.QLayout, QtGui.QLabel, QtGui.QLCDNumber, QtGui.QKeyEventTransition, QtGui.QItemSelectionModel, QtGui.QItemDelegate, QtGui.QIntValidator, QtGui.QInputDialog, QtGui.QInputContextPlugin, QtGui.QInputContext, QtGui.QImageIOPlugin, QtGui.QIconEnginePluginV2, QtGui.QIconEnginePlugin, QtCore.QVariantAnimation, QtGui.QHeaderView, QtGui.QHBoxLayout, QtGui.QGroupBox, QtCore.QTranslator, QtGui.QGridLayout, QtCore.QTimer, QtCore.QTimeLine, QtGui.QGraphicsWidget, QtCore.QTextCodecPlugin, QtGui.QGraphicsView, QtGui.QGraphicsTransform, QtGui.QGraphicsTextItem, QtCore.QTemporaryFile, QtCore.QStateMachine, QtCore.QState, QtCore.QSocketNotifier, QtGui.QGraphicsScene, QtCore.QSignalTransition, QtGui.QGraphicsScale, QtCore.QSignalMapper, QtGui.QGraphicsRotation, QtCore.QSharedMemory, QtGui.QGraphicsProxyWidget, QtCore.QSettings, QtCore.QSequentialAnimationGroup, QtGui.QGraphicsOpacityEffect, QtGui.QGraphicsObject, QtCore.QPropertyAnimation, QtGui.QGraphicsItemAnimation, QtCore.QProcess, QtCore.QPluginLoader, QtCore.QPauseAnimation, QtCore.QParallelAnimationGroup, QtCore.QObjectCleanupHandler, QtCore.QMimeData, QtGui.QGraphicsEffect, QtGui.QGraphicsDropShadowEffect, QtGui.QGraphicsColorizeEffect, QtGui.QGraphicsBlurEffect, QtGui.QGraphicsAnchor, QtGui.QGesture, QtGui.QFrame, QtGui.QFormLayout, QtGui.QFontDialog, QtGui.QFontComboBox, QtCore.QLibrary, QtGui.QFocusFrame, QtGui.QFileSystemModel, QtCore.QIODevice, QtCore.QHistoryState, QtGui.QFileDialog, QtGui.QErrorMessage, QtGui.QDrag, QtGui.QDoubleValidator, QtGui.QDoubleSpinBox, QtGui.QDockWidget, QtGui.QDirModel, QtGui.QDialogButtonBox, QtGui.QDialog, QtGui.QDial, QtGui.QDesktopWidget, QtCore.QFutureWatcherBase, QtCore.QFinalState, QtGui.QDateTimeEdit, QtCore.QFileSystemWatcher, QtGui.QDateEdit, QtGui.QDataWidgetMapper, QtCore.QFile, QtGui.QCompleter, QtCore.QEventTransition, QtGui.QCommonStyle, QtGui.QCommandLinkButton, QtCore.QEventLoop, QtGui.QComboBox, QtNetwork.QUdpSocket, QtNetwork.QTcpSocket, QtNetwork.QTcpServer, QtGui.QColumnView, QtGui.QColorDialog, QtNetwork.QSslSocket, QtGui.QClipboard, QtGui.QCheckBox, QtNetwork.QNetworkSession, QtGui.QCalendarWidget, QtGui.QButtonGroup, QtNetwork.QNetworkReply, QtCore.QCoreApplication, QtGui.QBoxLayout, QtNetwork.QNetworkDiskCache, QtNetwork.QNetworkCookieJar, QtGui.QApplication, QtNetwork.QNetworkConfigurationManager, QtGui.QActionGroup, QtSql.QSqlTableModel, QtGui.QAction, QtWebKit.QWebView, QtNetwork.QNetworkAccessManager, QtSql.QSqlRelationalTableModel, QtSql.QSqlRelationalDelegate, QtGui.QAbstractTextDocumentLayout, QtNetwork.QLocalSocket, QtNetwork.QLocalServer, QtGui.QAbstractSpinBox, QtCore.QBuffer, QtSql.QSqlQueryModel, QtWebKit.QWebPluginFactory, QtGui.QAbstractSlider, QtNetwork.QHttpMultiPart, QtOpenGL.QGLWidget, QtGui.QAbstractScrollArea, QtCore.QAnimationGroup, QtNetwork.QHttp, QtCore.QAbstractTransition, QtSql.QSqlDriverPlugin, QtCore.QAbstractTableModel, QtCore.QAbstractState, QtWebKit.QWebPage, QtCore.QAbstractListModel, QtOpenGL.QGLShaderProgram, QtGui.QAbstractProxyModel, QtSql.QSqlDriver, QtSvg.QSvgWidget, QtOpenGL.QGLShader, QtGui.QAbstractPrintDialog, QtSvg.QSvgRenderer, QtWebKit.QWebInspector, QtGui.QAbstractPageSetupDialog, QtSvg.QGraphicsSvgItem, QtWebKit.QWebHistoryInterface, QtCore.QAbstractItemModel, QtScript.QScriptExtensionPlugin, QtNetwork.QFtp, QtGui.QAbstractItemView, QtWebKit.QWebFrame, QtScript.QScriptEngine, QtGui.QAbstractItemDelegate, QtCore.QAbstractEventDispatcher, QtNetwork.QAbstractSocket, QtGui.QAbstractButton, QtXmlPatterns.QAbstractUriResolver, QtCore.QAbstractAnimation, QtUiTools.QUiLoader, QtXmlPatterns.QAbstractMessageHandler, and QtNetwork.QAbstractNetworkCache.
new void QtCore.QObject.DeleteLater | ( | ) |
Schedules this object for deletion.
The object will be deleted when control returns to the event loop. If the event loop is not running when this function is called (e.g. deleteLater() is called on an object before QCoreApplication::exec()), the object will be deleted once the event loop is started.
Note that entering and leaving a new event loop (e.g., by opening a modal dialog) will not perform the deferred deletion; for the object to be deleted, the control must return to the event loop from which deleteLater() was called.
Note: It is safe to call this function more than once; when the first deferred deletion event is delivered, any pending events for the object are removed from the event queue.
See also destroyed() and QPointer.
|
static |
Disconnects signal in object sender from method in object receiver. Returns true if the connection is successfully broken; otherwise returns false.
This function provides the same possibilities like disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method) but uses QMetaMethod to represent the signal and the method to be disconnected.
Additionally this function returnsfalse and no signals and slots disconnected if:
signal is not a member of sender class or one of its parent classes.
method is not a member of receiver class or one of its parent classes.
signal instance represents not a signal.
QMetaMethod() may be used as wildcard in the meaning "any signal" or "any slot in receiving object". In the same way 0 can be used for receiver in the meaning "any receiving object". In this case method should also be QMetaMethod(). sender parameter should be never 0.
This function was introduced in Qt 4.8.
See also disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method).
new bool QtCore.QObject.Disconnect | ( | QObject | receiver, |
string | member = null |
||
) |
This function overloads disconnect().
Disconnects all signals in this object from receiver's method.
A signal-slot connection is removed when either of the objects involved are destroyed.
|
static |
Disconnects signal in object sender from method in object receiver. Returns true if the connection is successfully broken; otherwise returns false.
A signal-slot connection is removed when either of the objects involved are destroyed.
disconnect() is typically used in three ways, as the following examples demonstrate.
Disconnect everything connected to an object's signals: disconnect(myObject, 0, 0, 0);
equivalent to the non-static overloaded function
myObject->disconnect();
Disconnect everything connected to a specific signal: disconnect(myObject, SIGNAL(mySignal()), 0, 0);
equivalent to the non-static overloaded function
myObject->disconnect(SIGNAL(mySignal()));
Disconnect a specific receiver: disconnect(myObject, 0, myReceiver, 0);
equivalent to the non-static overloaded function
myObject->disconnect(myReceiver);
new bool QtCore.QObject.Disconnect | ( | string | signal = null , |
QObject | receiver = null , |
||
string | member = null |
||
) |
This function overloads disconnect().
Disconnects signal from method of receiver.
A signal-slot connection is removed when either of the objects involved are destroyed.
Note: This function is thread-safe.
|
protectedvirtual |
This virtual function is called when something has been disconnected from signal in this object.
See connectNotify() for an example of how to compare signal with a specific signal.
Warning: This function violates the object-oriented principle of modularity. However, it might be useful for optimizing access to expensive resources.
See also disconnect() and connectNotify().
Reimplemented in QtCore.QFutureWatcherBase, QtNetwork.QNetworkSession, and QtCore.QBuffer.
new void QtCore.QObject.Dispose | ( | ) |
new void QtCore.QObject.DumpObjectInfo | ( | ) |
Dumps information about signal connections, etc. for this object to the debug output.
This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).
See also dumpObjectTree().
new void QtCore.QObject.DumpObjectTree | ( | ) |
Dumps a tree of children to the debug output.
This function is useful for debugging, but does nothing if the library has been compiled in release mode (i.e. without debugging information).
See also dumpObjectInfo().
new System.Collections.Generic.List<QByteArray> QtCore.QObject.DynamicPropertyNames | ( | ) |
Returns the names of all properties that were dynamically added to the object using setProperty().
This function was introduced in Qt 4.2.
Filters events if this object has been installed as an event filter for the watched object.
In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
Example:
class MainWindow : public QMainWindow
{
public:
MainWindow();
protected:
bool eventFilter(QObject <em>obj, QEvent *ev);
private:
QTextEdit *textEdit;
};
MainWindow::MainWindow()
{
textEdit = new QTextEdit;
setCentralWidget(textEdit);
textEdit->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == textEdit) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent>(event);
qDebug() << "Ate key press" << keyEvent->key();
return true;
} else {
return false;
}
} else {
// pass the event on to the parent class
return QMainWindow::eventFilter(obj, event);
}
}
Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.
Warning: If you delete the receiver object in this function, be sure to return true. Otherwise, Qt will forward the event to the deleted object and the program might crash.
See also installEventFilter().
Reimplemented in QtGui.QWorkspace, QtGui.QWidgetAction, QtGui.QSizeGrip, QtGui.QScrollArea, QtGui.QMenuBar, QtGui.QFocusFrame, QtGui.QDialog, and QtGui.QCompleter.
new bool QtCore.QObject.Inherits | ( | string | classname | ) |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
A class is considered to inherit itself.
Example:
QTimer *timer = new QTimer; // QTimer inherits QObject
timer->inherits("QTimer"); // returns true
timer->inherits("QObject"); // returns true
timer->inherits("QAbstractButton"); // returns false
// QVBoxLayout inherits QObject and QLayoutItem
QVBoxLayout *layout = new QVBoxLayout;
layout->inherits("QObject"); // returns true
layout->inherits("QLayoutItem"); // returns true (even though QLayoutItem is not a QObject)
If you need to determine whether an object is an instance of a particular class for the purpose of casting it, consider using qobject_cast<Type *>(object) instead.
See also metaObject() and qobject_cast().
new void QtCore.QObject.InstallEventFilter | ( | QObject | arg1 | ) |
Installs an event filter filterObj on this object. For example:
monitoredObj->installEventFilter(filterObj);
An 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 filterObj receives events via its eventFilter() function. The eventFilter() function must return true if the event should be filtered, (i.e. stopped); otherwise it must return false.
If multiple event filters are installed on a single object, the filter that was installed last is activated first.
Here's a KeyPressEater class that eats the key presses of its monitored objects:
class KeyPressEater : public QObject
{
Q_OBJECT
...
protected:
bool eventFilter(QObject *obj, QEvent *event);
};
bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
qDebug("Ate key press d", keyEvent->key());
return true;
} else {
// standard event processing
return QObject::eventFilter(obj, event);
}
}
And here's how to install it on two widgets:
KeyPressEater *keyPressEater = new KeyPressEater(this);
QPushButton *pushButton = new QPushButton(this);
QListView *listView = new QListView(this);
pushButton->installEventFilter(keyPressEater);
listView->installEventFilter(keyPressEater);
The QShortcut class, for example, uses this technique to intercept shortcut key presses.
Warning: 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.
Note that the filtering object must be in the same thread as this object. If filterObj is in a different thread, this function does nothing. If either filterObj or this object are moved to a different thread after calling this function, the event filter will not be called until both objects have the same thread affinity again (it is not removed).
See also removeEventFilter(), eventFilter(), and event().
new bool QtCore.QObject.IsWidgetType | ( | ) |
Returns true if the object is a widget; otherwise returns false.
Calling this function is equivalent to calling inherits("QWidget"), except that it is much faster.
new void QtCore.QObject.KillTimer | ( | int | id | ) |
Kills the timer with timer identifier, id.
The timer identifier is returned by startTimer() when a timer event is started.
See also timerEvent() and startTimer().
|
protectedvirtual |
This event handler can be reimplemented in a subclass to receive child events. The event is passed in the event parameter.
QEvent::ChildAdded and QEvent::ChildRemoved events are sent to objects when children are added or removed. In both cases you can only rely on the child being a QObject, or if isWidgetType() returns true, a QWidget. (This is because, in the ChildAdded case, the child is not yet fully constructed, and in the ChildRemoved case it might have been destructed already).
QEvent::ChildPolished events are sent to widgets when children are polished, or when polished children are added. If you receive a child polished event, the child's construction is usually completed. However, this is not guaranteed, and multiple polish events may be delivered during the execution of a widget's constructor.
For every child widget, you receive one ChildAdded event, zero or more ChildPolished events, and one ChildRemoved event.
The ChildPolished event is omitted if a child is removed immediately after it is added. If a child is polished several times during construction and destruction, you may receive several child polished events for the same child, each time with a different virtual table.
See also event().
Reimplemented in QtGui.QWorkspace, QtGui.QSplitter, QtGui.QMdiSubWindow, QtGui.QMdiArea, and QtGui.QLayout.
|
protectedvirtual |
This event handler can be reimplemented in a subclass to receive custom events. Custom events are user-defined events with a type value at least as large as the QEvent::User item of the QEvent::Type enum, and is typically a QEvent subclass. The event is passed in the event parameter.
See also event() and QEvent.
|
protected |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked.
All the objects's children are destroyed immediately after this signal is emitted.
See also deleteLater() and QPointer.
|
virtual |
This virtual function receives events to an object and should return true if the event e was recognized and processed.
The event() function can be reimplemented to customize the behavior of an object.
See also installEventFilter(), timerEvent(), QApplication::sendEvent(), QApplication::postEvent(), and QWidget::event().
Reimplemented in QtGui.QWorkspace, QtGui.QWidgetAction, QtGui.QWidget, QtGui.QTreeWidget, QtGui.QToolButton, QtGui.QToolBox, QtGui.QTextEdit, QtGui.QTextBrowser, QtGui.QTableWidget, QtGui.QTabWidget, QtGui.QTabBar, QtGui.QStatusBar, QtGui.QStackedWidget, QtGui.QSplitterHandle, QtGui.QSplitter, QtGui.QSplashScreen, QtGui.QSizeGrip, QtGui.QShortcut, QtGui.QScrollArea, QtGui.QRubberBand, QtGui.QRadioButton, QtGui.QPushButton, QtGui.QProxyStyle, QtGui.QProgressBar, QtGui.QPlainTextEdit, QtGui.QMessageBox, QtGui.QMenuBar, QtGui.QMenu, QtGui.QListWidget, QtGui.QListView, QtGui.QLineEdit, QtGui.QLabel, QtGui.QLCDNumber, QtGui.QHeaderView, QtCore.QStateMachine, QtCore.QState, QtCore.QSocketNotifier, QtCore.QSignalTransition, QtCore.QPauseAnimation, QtGui.QFrame, QtGui.QFontComboBox, QtGui.QFocusFrame, QtCore.QHistoryState, QtGui.QDial, QtCore.QFinalState, QtGui.QCompleter, QtCore.QEventTransition, QtGui.QCommandLinkButton, QtGui.QClipboard, QtGui.QCheckBox, QtCore.QCoreApplication, QtGui.QApplication, QtGui.QAction, QtWebKit.QWebView, QtGui.QAbstractSlider, QtOpenGL.QGLWidget, QtGui.QAbstractScrollArea, QtCore.QAbstractTransition, QtWebKit.QWebPage, QtCore.QAbstractState, QtWebKit.QWebInspector, QtWebKit.QWebFrame, and QtGui.QAbstractButton.
|
protectedvirtual |
This event handler can be reimplemented in a subclass to receive timer events for the object.
QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.
See also startTimer(), killTimer(), and event().
Reimplemented in QtGui.QToolButton, QtGui.QTextEdit, QtGui.QPlainTextEdit, QtGui.QMenuBar, QtGui.QMenu, QtGui.QMdiSubWindow, QtGui.QMdiArea, QtGui.QListView, QtCore.QTimer, QtGui.QAbstractSlider, and QtGui.QAbstractButton.
new object QtCore.QObject.Property | ( | string | name | ) |
Returns the value of the object's name property.
If no such property exists, the returned variant is invalid.
Information about all available properties is provided through the metaObject() and dynamicPropertyNames().
See also setProperty(), QVariant::isValid(), metaObject(), and dynamicPropertyNames().
|
protected |
Returns the number of receivers connected to the signal.
Since both slots and signals can be used as receivers for signals, and the same connections can be made many times, the number of receivers is the same as the number of connections made from this signal.
When calling this function, you can use the SIGNAL() macro to pass a specific signal:
if (receivers(SIGNAL(valueChanged(QByteArray))) > 0) {
QByteArray data;
get_the_value(&data); // expensive operation
emit valueChanged(data);
}
As the code snippet above illustrates, you can use this function to avoid emitting a signal that nobody listens to.
Warning: 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.
|
static |
new void QtCore.QObject.RemoveEventFilter | ( | QObject | arg1 | ) |
Removes an event filter object obj from this object. The request is ignored if such an event filter has not been installed.
All event filters for this object are automatically removed when this object is destroyed.
It is always safe to remove an event filter, even during event filter activation (i.e. from the eventFilter() function).
See also installEventFilter(), eventFilter(), and event().
|
protected |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. The pointer is valid only during the execution of the slot that calls this function from this object's thread context.
The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.
Warning: This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot.
Warning: As mentioned above, the return value of this function is not valid when the slot is called via a Qt::DirectConnection from a thread different from this object's thread. Do not use this function in this type of scenario.
See also senderSignalIndex() and QSignalMapper.
|
protected |
Returns the meta-method index of the signal that called the currently executing slot, which is a member of the class returned by sender(). If called outside of a slot activated by a signal, -1 is returned.
For signals with default parameters, this function will always return the index with all parameters, regardless of which was used with connect(). For example, the signal destroyed(QObject *obj = 0) will have two different indexes (with and without the parameter), but this function will always return the index with a parameter. This does not apply when overloading signals with different parameters.
Warning: This function violates the object-oriented principle of modularity. However, getting access to the signal index might be useful when many signals are connected to a single slot.
Warning: The return value of this function is not valid when the slot is called via a Qt::DirectConnection from a thread different from this object's thread. Do not use this function in this type of scenario.
This function was introduced in Qt 4.8.
See also sender(), QMetaObject::indexOfSignal(), and QMetaObject::method().
new bool QtCore.QObject.SetProperty | ( | string | name, |
object | value | ||
) |
Sets the value of the object's name property to 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.
See also property(), metaObject(), and dynamicPropertyNames().
new void QtCore.QObject.SetUserData | ( | uint | id, |
QObjectUserData | data | ||
) |
new bool QtCore.QObject.SignalsBlocked | ( | ) |
Returns true if signals are blocked; otherwise returns false.
Signals are not blocked by default.
See also blockSignals().
new int QtCore.QObject.StartTimer | ( | int | interval | ) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.
A timer event will occur every interval milliseconds until killTimer() is called. If interval is 0, then the timer event occurs once every time there are no more window system events to process.
The virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.
If multiple timers are running, the QTimerEvent::timerId() can be used to find out which timer was activated.
Example:
class MyObject : public QObject
{
Q_OBJECT
public:
MyObject(QObject *parent = 0);
protected:
void timerEvent(QTimerEvent *event);
};
MyObject::MyObject(QObject *parent)
: QObject(parent)
{
startTimer(50); // 50-millisecond timer
startTimer(1000); // 1-second timer
startTimer(60000); // 1-minute timer
}
void MyObject::timerEvent(QTimerEvent *event)
{
qDebug() << "Timer ID:" << event->timerId();
}
Note that QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 20 milliseconds; some provide more. If Qt is unable to deliver the requested number of timer events, it will silently discard some.
The QTimer class provides a high-level programming interface with single-shot timers and timer signals instead of events. There is also a QBasicTimer class that is more lightweight than QTimer and less clumsy than using timer IDs directly.
See also timerEvent(), killTimer(), and QTimer::singleShot().
|
static |
Returns a translated version of sourceText, optionally based on a disambiguation string and value of n for strings containing plurals; otherwise returns sourceText itself if no appropriate translated string is available.
Example:
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
...
If the same sourceText is used in different roles within the same context, an additional identifying string may be passed in disambiguation (0 by default). In Qt 4.4 and earlier, this was the preferred way to pass comments to translators.
Example:
MyWindow::MyWindow()
{
QLabel *senderLabel = new QLabel(tr("Name:"));
QLabel *recipientLabel = new QLabel(tr("Name:", "recipient"));
...
See Writing Source Code for Translation for a detailed description of Qt's translation mechanisms in general, and the Disambiguation section for information on disambiguation.
Warning: This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
See also trUtf8(), QApplication::translate(), QTextCodec::setCodecForTr(), and Internationalization with Qt.
|
static |
Returns a translated version of sourceText, optionally based on a disambiguation string and value of n for strings containing plurals; otherwise returns sourceText itself if no appropriate translated string is available.
Example:
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
...
If the same sourceText is used in different roles within the same context, an additional identifying string may be passed in disambiguation (0 by default). In Qt 4.4 and earlier, this was the preferred way to pass comments to translators.
Example:
MyWindow::MyWindow()
{
QLabel *senderLabel = new QLabel(tr("Name:"));
QLabel *recipientLabel = new QLabel(tr("Name:", "recipient"));
...
See Writing Source Code for Translation for a detailed description of Qt's translation mechanisms in general, and the Disambiguation section for information on disambiguation.
Warning: This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
See also trUtf8(), QApplication::translate(), QTextCodec::setCodecForTr(), and Internationalization with Qt.
|
static |
Returns a translated version of sourceText, or QString::fromUtf8(sourceText) if there is no appropriate version. It is otherwise identical to tr(sourceText, disambiguation, n).
Note that using the Utf8 variants of the translation functions is not required if CODECFORTR is already set to UTF-8 in the qmake project file and QTextCodec::setCodecForTr("UTF-8") is used.
Warning: This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
Warning: For portability reasons, we recommend that you use escape sequences for specifying non-ASCII characters in string literals to trUtf8(). For example:
label->setText(tr("F\374r \310lise"));
See also tr(), QApplication::translate(), and Internationalization with Qt.
|
static |
Returns a translated version of sourceText, or QString::fromUtf8(sourceText) if there is no appropriate version. It is otherwise identical to tr(sourceText, disambiguation, n).
Note that using the Utf8 variants of the translation functions is not required if CODECFORTR is already set to UTF-8 in the qmake project file and QTextCodec::setCodecForTr("UTF-8") is used.
Warning: This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will probably result in crashes or other undesirable behavior.
Warning: For portability reasons, we recommend that you use escape sequences for specifying non-ASCII characters in string literals to trUtf8(). For example:
label->setText(tr("F\374r \310lise"));
See also tr(), QApplication::translate(), and Internationalization with Qt.
new QObjectUserData QtCore.QObject.UserData | ( | uint | id | ) |
|
protected |
|
protected |
|
protected |
|
addremove |
This event handler can be reimplemented in a subclass to receive child events. The event is passed in the event parameter.
QEvent::ChildAdded and QEvent::ChildRemoved events are sent to objects when children are added or removed. In both cases you can only rely on the child being a QObject, or if isWidgetType() returns true, a QWidget. (This is because, in the ChildAdded case, the child is not yet fully constructed, and in the ChildRemoved case it might have been destructed already).
QEvent::ChildPolished events are sent to widgets when children are polished, or when polished children are added. If you receive a child polished event, the child's construction is usually completed. However, this is not guaranteed, and multiple polish events may be delivered during the execution of a widget's constructor.
For every child widget, you receive one ChildAdded event, zero or more ChildPolished events, and one ChildRemoved event.
The ChildPolished event is omitted if a child is removed immediately after it is added. If a child is polished several times during construction and destruction, you may receive several child polished events for the same child, each time with a different virtual table.
See also event().
|
addremove |
This event handler can be reimplemented in a subclass to receive custom events. Custom events are user-defined events with a type value at least as large as the QEvent::User item of the QEvent::Type enum, and is typically a QEvent subclass. The event is passed in the event parameter.
See also event() and QEvent.
|
addremove |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked.
All the objects's children are destroyed immediately after this signal is emitted.
See also deleteLater() and QPointer.
|
addremove |
|
getprotected |
|
addremove |
This virtual function receives events to an object and should return true if the event e was recognized and processed.
The event() function can be reimplemented to customize the behavior of an object.
See also installEventFilter(), timerEvent(), QApplication::sendEvent(), QApplication::postEvent(), and QWidget::event().
|
getset |
This property holds the name of this object.
You can find an object by name (and type) using findChild(). You can find a set of objects with findChildren().
qDebug("MyClass::setPrecision(): (s) invalid precision f",
qPrintable(objectName()), newPrecision);
By default, this property contains an empty string.
|
getset |
Returns a pointer to the parent object.
Makes the object a child of parent.
|
getset |
|
staticget |
This variable stores the meta-object for the class.
A meta-object contains information about a class that inherits QObject, e.g. class name, superclass name, properties, signals and slots. Every class that contains the Q_OBJECT macro will also have a meta-object.
The meta-object information is required by the signal/slot connection mechanism and the property system. The inherits() function also makes use of the meta-object.
If you have a pointer to an object, you can use metaObject() to retrieve the meta-object associated with that object.
Example:
QPushButton::staticMetaObject.className(); // returns "QPushButton"
QObject *obj = new QPushButton;
obj->metaObject()->className(); // returns "QPushButton"
See also metaObject().
|
staticgetprotected |
|
addremove |
This event handler can be reimplemented in a subclass to receive timer events for the object.
QTimer provides a higher-level interface to the timer functionality, and also more general information about timers. The timer event is passed in the event parameter.
See also startTimer(), killTimer(), and event().