diff options
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index a7f48b5c59..35e503d330 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1001,7 +1001,7 @@ QObject::~QObject() emit destroyed(this); } - if (d->declarativeData && QAbstractDeclarativeData::destroyed) + if (!d->isDeletingChildren && d->declarativeData && QAbstractDeclarativeData::destroyed) QAbstractDeclarativeData::destroyed(d->declarativeData, this); QObjectPrivate::ConnectionData *cd = d->connections.loadRelaxed(); @@ -2155,7 +2155,7 @@ void QObjectPrivate::deleteChildren() // delete children objects // don't use qDeleteAll as the destructor of the child might // delete siblings - for (int i = 0; i < children.count(); ++i) { + for (int i = 0; i < children.size(); ++i) { currentChildBeingDeleted = children.at(i); children[i] = nullptr; delete currentChildBeingDeleted; @@ -2303,7 +2303,7 @@ void QObject::removeEventFilter(QObject *obj) { Q_D(QObject); if (d->extraData) { - for (int i = 0; i < d->extraData->eventFilters.count(); ++i) { + for (int i = 0; i < d->extraData->eventFilters.size(); ++i) { if (d->extraData->eventFilters.at(i) == obj) d->extraData->eventFilters[i] = nullptr; } @@ -2625,7 +2625,7 @@ int QObject::receivers(const char *signal) const if (!d->isSignalConnected(signal_index)) return receivers; - if (d->declarativeData && QAbstractDeclarativeData::receivers) { + if (!d->isDeletingChildren && d->declarativeData && QAbstractDeclarativeData::receivers) { receivers += QAbstractDeclarativeData::receivers(d->declarativeData, this, signal_index); } @@ -2653,13 +2653,15 @@ int QObject::receivers(const char *signal) const \snippet code/src_corelib_kernel_qobject.cpp 49 - As the code snippet above illustrates, you can use this function - to avoid emitting a signal that nobody listens to. + As the code snippet above illustrates, you can use this function to avoid + expensive initialization or emitting a signal that nobody listens to. + However, in a multithreaded application, connections might change after + this function returns and before the signal gets emitted. \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. + modularity. In particular, this function must not be called from an + override of connectNotify() or disconnectNotify(), as those might get + called from any thread. */ bool QObject::isSignalConnected(const QMetaMethod &signal) const { @@ -3333,8 +3335,13 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal, signal. \warning This function is called from the thread which performs the - connection, which may be a different thread from the thread in - which this object lives. + connection, which may be a different thread from the thread in which + this object lives. This function may also be called with a QObject internal + mutex locked. It is therefore not allowed to re-enter any QObject + functions, including isSignalConnected(), from your reimplementation. If + you lock a mutex in your reimplementation, make sure that you don't call + QObject functions with that mutex held in other places or it will result in + a deadlock. \sa connect(), disconnectNotify() */ @@ -3363,12 +3370,12 @@ void QObject::connectNotify(const QMetaMethod &signal) expensive resources. \warning This function is called from the thread which performs the - disconnection, which may be a different thread from the thread in - which this object lives. This function may also be called with a QObject - internal mutex locked. It is therefore not allowed to re-enter any - of any QObject functions from your reimplementation and if you lock - a mutex in your reimplementation, make sure that you don't call QObject - functions with that mutex held in other places or it will result in + disconnection, which may be a different thread from the thread in which + this object lives. This function may also be called with a QObject internal + mutex locked. It is therefore not allowed to re-enter any QObject + functions, including isSignalConnected(), from your reimplementation. If + you lock a mutex in your reimplementation, make sure that you don't call + QObject functions with that mutex held in other places or it will result in a deadlock. \sa disconnect(), connectNotify() @@ -3684,7 +3691,7 @@ void QMetaObject::connectSlotsByName(QObject *o) // ...we check each object in our list, ... bool foundIt = false; - for (int j = 0; j < list.count(); ++j) { + for (int j = 0; j < list.size(); ++j) { const QObject *co = list.at(j); const QByteArray coName = co->objectName().toLatin1(); |