From 6f0f9f69288925ef423c542ef5eb7302a5431867 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Tue, 22 Nov 2011 14:45:35 +0100 Subject: Remove QMetaObject guards and deprecate QPointer. QWeakPointer is superior and preferred. Remove QMetaObject::addGuard(), QMetaObject::changeGuard(), QMetaObject::removeGuard(), and QObjectPrivate::clearGuards(). Implement QPointer using QWeakPointer instead. This changes the behavior of QPointer in 2 ways: - During destruction of a QWidget. Previously, the destructor of QWidget would reset all QPointers so that they would return zero when destroying children. Update tst_QPointer to account for this change. - When constructing a QSharedPointer to take ownership of an object after a QPointer is already tracking the object. Previously, the shared pointer construction would not be affected by the QPointer, but now that QPointer is implemented using QWeakPoiner, constructing the QSharedPointer will cause an abort(). Fix tst_QSharedPointer by removing the use of QPointer in the objectCast() test. These behavior changes are documented in the QPointer class documentation and in the changes file. Change-Id: I92d0276219c076ece7bcb60f6e1b9120ce4f5747 Reviewed-by: Lars Knoll Reviewed-by: Olivier Goffart --- src/widgets/kernel/qaction.cpp | 9 +++------ src/widgets/kernel/qwidget.cpp | 4 ---- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qaction.cpp b/src/widgets/kernel/qaction.cpp index 22162895f7..15954abf8c 100644 --- a/src/widgets/kernel/qaction.cpp +++ b/src/widgets/kernel/qaction.cpp @@ -1185,22 +1185,19 @@ void QAction::activate(ActionEvent event) { Q_D(QAction); if(event == Trigger) { - QObject *guard = this; - QMetaObject::addGuard(&guard); + QWeakPointer guard = this; if(d->checkable) { // the checked action of an exclusive group cannot be unchecked if (d->checked && (d->group && d->group->isExclusive() && d->group->checkedAction() == this)) { - if (guard) + if (!guard.isNull()) emit triggered(true); - QMetaObject::removeGuard(&guard); return; } setChecked(!d->checked); } - if (guard) + if (!guard.isNull()) emit triggered(d->checked); - QMetaObject::removeGuard(&guard); } else if(event == Hover) { emit hovered(); } diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 7ec37bb929..d20e979cfb 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1469,10 +1469,6 @@ QWidget::~QWidget() delete d->needsFlush; d->needsFlush = 0; - // set all QPointers for this object to zero - if (d->hasGuards) - QObjectPrivate::clearGuards(this); - if (d->declarativeData) { QAbstractDeclarativeData::destroyed(d->declarativeData, this); d->declarativeData = 0; // don't activate again in ~QObject -- cgit v1.2.3