Use QPointer instead of QWeakPointer.
authorStephen Kelly <stephen.kelly@kdab.com>
Wed, 30 May 2012 11:53:24 +0000 (13:53 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 5 Jun 2012 16:42:26 +0000 (18:42 +0200)
The use of QWeakPointer for tracking QObject pointers is to be
deprecated.

Change-Id: If460ca7f515db77af24030152f4bd56e1a5fae7c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
26 files changed:
src/corelib/animation/qabstractanimation.cpp
src/corelib/animation/qpropertyanimation_p.h
src/corelib/plugin/qlibrary_p.h
src/corelib/statemachine/qabstracttransition_p.h
src/corelib/statemachine/qstate.cpp
src/gui/kernel/qguiapplication.cpp
src/gui/kernel/qguiapplication_p.h
src/gui/kernel/qinputmethod_p.h
src/gui/kernel/qwindowsysteminterface_qpa_p.h
src/network/access/qnetworkrequest_p.h
src/plugins/platforms/xcb/qxcbdrag.h
src/widgets/dialogs/qdialog.cpp
src/widgets/graphicsview/qgraphicsscene.cpp
src/widgets/itemviews/qabstractitemview_p.h
src/widgets/kernel/qaction.cpp
src/widgets/kernel/qapplication.cpp
src/widgets/kernel/qwidget.cpp
src/widgets/kernel/qwidgetwindow_qpa_p.h
src/widgets/widgets/qdatetimeedit.cpp
src/widgets/widgets/qdatetimeedit_p.h
src/widgets/widgets/qmenu.cpp
tests/auto/corelib/thread/qthread/tst_qthread.cpp
tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
tests/auto/other/gestures/tst_gestures.cpp
tests/auto/other/qsharedpointer_and_qwidget/tst_qsharedpointer_and_qwidget.cpp
tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp

index 969a547..e56d1e2 100644 (file)
@@ -925,7 +925,7 @@ void QAbstractAnimationPrivate::setState(QAbstractAnimation::State newState)
     }
 
     state = newState;
-    QWeakPointer<QAbstractAnimation> guard(q);
+    QPointer<QAbstractAnimation> guard(q);
 
     //(un)registration of the animation must always happen before calls to
     //virtual function (updateState) to ensure a correct state of the timer
index c413c68..d6c0f90 100644 (file)
@@ -70,7 +70,7 @@ public:
     {
     }
 
-    QWeakPointer<QObject> target;
+    QPointer<QObject> target;
     //we use targetValue to be able to unregister the target from the global hash
     QObject *targetValue;
 
index 604a5fb..ca7b5d9 100644 (file)
@@ -96,7 +96,7 @@ public:
     static QVector<QStaticPlugin> staticPlugins();
 
 
-    QWeakPointer<QObject> inst;
+    QPointer<QObject> inst;
     QtPluginInstanceFunction instance;
     QJsonObject metaData;
     bool compatPlugin;
index 64a0af7..4423988 100644 (file)
@@ -80,7 +80,7 @@ public:
     QStateMachine *machine() const;
     void emitTriggered();
 
-    QList<QWeakPointer<QAbstractState> > targetStates;
+    QList<QPointer<QAbstractState> > targetStates;
 
 #ifndef QT_NO_ANIMATION
     QList<QAbstractAnimation*> animations;
index 0230acb..14432ed 100644 (file)
@@ -299,7 +299,7 @@ void QState::addTransition(QAbstractTransition *transition)
     }
 
     transition->setParent(this);
-    const QList<QWeakPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates;
+    const QList<QPointer<QAbstractState> > &targets = QAbstractTransitionPrivate::get(transition)->targetStates;
     for (int i = 0; i < targets.size(); ++i) {
         QAbstractState *t = targets.at(i).data();
         if (!t) {
index 05e1274..f71e611 100644 (file)
@@ -1604,7 +1604,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
         touchPoint.d = touchPoint.d->detach();
 
         // update state
-        QWeakPointer<QWindow> w;
+        QPointer<QWindow> w;
         QTouchEvent::TouchPoint previousTouchPoint;
         ActiveTouchPointsKey touchInfoKey(e->device, touchPoint.id());
         ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey];
@@ -1613,7 +1613,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
             if (e->device->type() == QTouchDevice::TouchPad) {
                 // on touch-pads, send all touch points to the same widget
                 w = d->activeTouchPoints.isEmpty()
-                    ? QWeakPointer<QWindow>()
+                    ? QPointer<QWindow>()
                     : d->activeTouchPoints.constBegin().value().window;
             }
 
index 8b7977e..e79c2af 100644 (file)
@@ -205,8 +205,8 @@ public:
         int touchPointId;
     };
     struct ActiveTouchPointsValue {
-        QWeakPointer<QWindow> window;
-        QWeakPointer<QObject> target;
+        QPointer<QWindow> window;
+        QPointer<QObject> target;
         QTouchEvent::TouchPoint touchPoint;
     };
     QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
@@ -216,7 +216,7 @@ public:
             : pos(p), screenPos(sp), window(w) { }
         QPointF pos;
         QPointF screenPos;
-        QWeakPointer<QWindow> window;
+        QPointer<QWindow> window;
     };
     QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
 
index ad3d214..7b24ebe 100644 (file)
@@ -85,7 +85,7 @@ public:
     bool objectAcceptsInputMethod(QObject *object);
 
     QTransform inputItemTransform;
-    QWeakPointer<QObject> inputItem;
+    QPointer<QObject> inputItem;
     QPlatformInputContext *testContext;
 };
 
index 3eebaf2..919a7de 100644 (file)
@@ -44,6 +44,7 @@
 #include "qwindowsysteminterface_qpa.h"
 
 #include <QElapsedTimer>
+#include <QPointer>
 
 QT_BEGIN_HEADER
 
@@ -88,7 +89,7 @@ public:
     public:
         explicit CloseEvent(QWindow *w)
             : WindowSystemEvent(Close), window(w) { }
-        QWeakPointer<QWindow> window;
+        QPointer<QWindow> window;
     };
 
     class GeometryChangeEvent : public WindowSystemEvent {
@@ -96,7 +97,7 @@ public:
         GeometryChangeEvent(QWindow *tlw, const QRect &newGeometry)
             : WindowSystemEvent(GeometryChange), tlw(tlw), newGeometry(newGeometry)
         { }
-        QWeakPointer<QWindow> tlw;
+        QPointer<QWindow> tlw;
         QRect newGeometry;
     };
 
@@ -105,7 +106,7 @@ public:
         explicit EnterEvent(QWindow *enter)
             : WindowSystemEvent(Enter), enter(enter)
         { }
-        QWeakPointer<QWindow> enter;
+        QPointer<QWindow> enter;
     };
 
     class LeaveEvent : public WindowSystemEvent {
@@ -113,7 +114,7 @@ public:
         explicit LeaveEvent(QWindow *leave)
             : WindowSystemEvent(Leave), leave(leave)
         { }
-        QWeakPointer<QWindow> leave;
+        QPointer<QWindow> leave;
     };
 
     class ActivatedWindowEvent : public WindowSystemEvent {
@@ -121,7 +122,7 @@ public:
         explicit ActivatedWindowEvent(QWindow *activatedWindow)
             : WindowSystemEvent(ActivatedWindow), activated(activatedWindow)
         { }
-        QWeakPointer<QWindow> activated;
+        QPointer<QWindow> activated;
     };
 
     class WindowStateChangedEvent : public WindowSystemEvent {
@@ -130,7 +131,7 @@ public:
             : WindowSystemEvent(WindowStateChanged), window(_window), newState(_newState)
         { }
 
-        QWeakPointer<QWindow> window;
+        QPointer<QWindow> window;
         Qt::WindowState newState;
     };
 
@@ -138,7 +139,7 @@ public:
     public:
         UserEvent(QWindow * w, ulong time, EventType t)
             : WindowSystemEvent(t), window(w), nullWindow(w == 0), timestamp(time) { }
-        QWeakPointer<QWindow> window;
+        QPointer<QWindow> window;
         bool nullWindow;
         unsigned long timestamp;
     };
@@ -209,7 +210,7 @@ public:
     public:
         ScreenOrientationEvent(QScreen *s, Qt::ScreenOrientation o)
             : WindowSystemEvent(ScreenOrientation), screen(s), orientation(o) { }
-        QWeakPointer<QScreen> screen;
+        QPointer<QScreen> screen;
         Qt::ScreenOrientation orientation;
     };
 
@@ -217,7 +218,7 @@ public:
     public:
         ScreenGeometryEvent(QScreen *s, const QRect &g)
             : WindowSystemEvent(ScreenGeometry), screen(s), geometry(g) { }
-        QWeakPointer<QScreen> screen;
+        QPointer<QScreen> screen;
         QRect geometry;
     };
 
@@ -225,7 +226,7 @@ public:
     public:
         ScreenAvailableGeometryEvent(QScreen *s, const QRect &g)
             : WindowSystemEvent(ScreenAvailableGeometry), screen(s), availableGeometry(g) { }
-        QWeakPointer<QScreen> screen;
+        QPointer<QScreen> screen;
         QRect availableGeometry;
     };
 
@@ -233,7 +234,7 @@ public:
     public:
         ScreenLogicalDotsPerInchEvent(QScreen *s, qreal dx, qreal dy)
             : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s), dpiX(dx), dpiY(dy) { }
-        QWeakPointer<QScreen> screen;
+        QPointer<QScreen> screen;
         qreal dpiX;
         qreal dpiY;
     };
@@ -242,7 +243,7 @@ public:
     public:
         ScreenRefreshRateEvent(QScreen *s, qreal r)
             : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
-        QWeakPointer<QScreen> screen;
+        QPointer<QScreen> screen;
         qreal rate;
     };
 
@@ -250,13 +251,13 @@ public:
     public:
         explicit ThemeChangeEvent(QWindow * w)
             : WindowSystemEvent(ThemeChange), window(w) { }
-        QWeakPointer<QWindow> window;
+        QPointer<QWindow> window;
     };
 
     class ExposeEvent : public WindowSystemEvent {
     public:
         ExposeEvent(QWindow *exposed, const QRegion &region);
-        QWeakPointer<QWindow> exposed;
+        QPointer<QWindow> exposed;
         bool isExposed;
         QRegion region;
     };
index 13861cc..0df886c 100644 (file)
@@ -59,6 +59,7 @@
 #include "QtCore/qhash.h"
 #include "QtCore/qshareddata.h"
 #include "QtCore/qsharedpointer.h"
+#include "QtCore/qpointer.h"
 
 QT_BEGIN_NAMESPACE
 
@@ -74,7 +75,7 @@ public:
     RawHeadersList rawHeaders;
     CookedHeadersMap cookedHeaders;
     AttributesMap attributes;
-    QWeakPointer<QObject> originatingObject;
+    QPointer<QObject> originatingObject;
 
     RawHeadersList::ConstIterator findRawHeader(const QByteArray &key) const;
     RawHeadersList allRawHeaders() const;
index b404d26..2666e59 100644 (file)
@@ -50,6 +50,7 @@
 #include <qpoint.h>
 #include <qrect.h>
 #include <qsharedpointer.h>
+#include <qpointer.h>
 #include <qvector.h>
 
 #include <qpixmap.h>
@@ -113,7 +114,7 @@ private:
     Qt::DropAction toDropAction(xcb_atom_t atom) const;
     xcb_atom_t toXdndAction(Qt::DropAction a) const;
 
-    QWeakPointer<QWindow> currentWindow;
+    QPointer<QWindow> currentWindow;
     QPoint currentPosition;
 
     QXcbDropData *dropData;
index 97a5b6d..0e57a16 100644 (file)
@@ -624,7 +624,7 @@ void QDialog::contextMenuEvent(QContextMenuEvent *e)
     while (w && w->whatsThis().size() == 0 && !w->testAttribute(Qt::WA_CustomWhatsThis))
         w = w->isWindow() ? 0 : w->parentWidget();
     if (w) {
-        QWeakPointer<QMenu> p = new QMenu(this);
+        QPointer<QMenu> p = new QMenu(this);
         QAction *wt = p.data()->addAction(tr("What's This?"));
         if (p.data()->exec(e->globalPos()) == wt) {
             QHelpEvent e(QEvent::WhatsThis, w->rect().center(),
index a63403a..6feeb94 100644 (file)
@@ -6067,7 +6067,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
         // initial gesture targets
         if (!conflictedGestures.isEmpty()) {
             for (int i = 0; i < cachedTargetItems.size(); ++i) {
-                QWeakPointer<QGraphicsObject> item = cachedTargetItems.at(i);
+                QPointer<QGraphicsObject> item = cachedTargetItems.at(i);
 
                 // get gestures to deliver to the current item
                 QSet<QGesture *> gestures = conflictedGestures & cachedItemGestures.value(item.data());
@@ -6153,7 +6153,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
     }
     qSort(cachedTargetItems.begin(), cachedTargetItems.end(), qt_closestItemFirst);
     for (int i = 0; i < cachedTargetItems.size(); ++i) {
-        QWeakPointer<QGraphicsObject> receiver = cachedTargetItems.at(i);
+        QPointer<QGraphicsObject> receiver = cachedTargetItems.at(i);
         QSet<QGesture *> gestures =
                 undeliveredGestures & cachedItemGestures.value(receiver.data());
         gestures -= cachedAlreadyDeliveredGestures.value(receiver.data());
index 3826f3b..63f7488 100644 (file)
 QT_BEGIN_NAMESPACE
 
 struct QEditorInfo {
-    QEditorInfo(QWidget *e, bool s): widget(QWeakPointer<QWidget>(e)), isStatic(s) {}
+    QEditorInfo(QWidget *e, bool s): widget(QPointer<QWidget>(e)), isStatic(s) {}
     QEditorInfo(): isStatic(false) {}
 
-    QWeakPointer<QWidget> widget;
+    QPointer<QWidget> widget;
     bool isStatic;
 };
 
index 0d500c8..05d250e 100644 (file)
@@ -1181,7 +1181,7 @@ void QAction::activate(ActionEvent event)
 {
     Q_D(QAction);
     if(event == Trigger) {
-        QWeakPointer<QObject> guard = this;
+        QPointer<QObject> guard = this;
         if(d->checkable) {
             // the checked action of an exclusive group cannot be  unchecked
             if (d->checked && (d->group && d->group->isExclusive()
index 1ca30c5..e9003e8 100644 (file)
@@ -3425,7 +3425,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
             bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents);
             touchEvent->setTarget(widget);
             touchEvent->setAccepted(acceptTouchEvents);
-            QWeakPointer<QWidget> p = widget;
+            QPointer<QWidget> p = widget;
             res = acceptTouchEvents && d->notify_helper(widget, touchEvent);
             eventAccepted = touchEvent->isAccepted();
             if (p.isNull()) {
@@ -4369,14 +4369,14 @@ void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
         touchPoint.d = touchPoint.d->detach();
 
         // update state
-        QWeakPointer<QObject> target;
+        QPointer<QObject> target;
         ActiveTouchPointsKey touchInfoKey(device, touchPoint.id());
         ActiveTouchPointsValue &touchInfo = d->activeTouchPoints[touchInfoKey];
         if (touchPoint.state() == Qt::TouchPointPressed) {
             if (device->type() == QTouchDevice::TouchPad) {
                 // on touch-pads, send all touch points to the same widget
                 target = d->activeTouchPoints.isEmpty()
-                        ? QWeakPointer<QObject>()
+                        ? QPointer<QObject>()
                         : d->activeTouchPoints.constBegin().value().target;
             }
 
index 454ffd5..e6a760a 100644 (file)
@@ -2459,7 +2459,7 @@ void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate, bool
     Q_Q(QWidget);
     QStyle *oldStyle  = q->style();
 #ifndef QT_NO_STYLE_STYLESHEET
-    QWeakPointer<QStyle> origStyle;
+    QPointer<QStyle> origStyle;
 #endif
 
 #ifdef Q_WS_MAC
index d4fd37c..8afa3f3 100644 (file)
@@ -95,9 +95,9 @@ private:
     void updateGeometry();
 
     QWidget *m_widget;
-    QWeakPointer<QWidget> m_implicit_mouse_grabber;
+    QPointer<QWidget> m_implicit_mouse_grabber;
 #ifndef QT_NO_DRAGANDDROP
-    QWeakPointer<QWidget> m_dragTarget;
+    QPointer<QWidget> m_dragTarget;
 #endif
 };
 
index 4c418bd..b916212 100644 (file)
@@ -2598,7 +2598,7 @@ void QCalendarPopup::setCalendarWidget(QCalendarWidget *cw)
         widgetLayout->setSpacing(0);
     }
     delete calendar.data();
-    calendar = QWeakPointer<QCalendarWidget>(cw);
+    calendar = QPointer<QCalendarWidget>(cw);
     widgetLayout->addWidget(cw);
 
     connect(cw, SIGNAL(activated(QDate)), this, SLOT(dateSelected(QDate)));
index 35f0f57..f7e6861 100644 (file)
@@ -173,7 +173,7 @@ protected:
 private:
     QCalendarWidget *verifyCalendarInstance();
 
-    QWeakPointer<QCalendarWidget> calendar;
+    QPointer<QCalendarWidget> calendar;
     QDate oldDate;
     bool dateChanged;
 };
index 8d50b03..4747d1c 100644 (file)
@@ -1098,7 +1098,7 @@ void QMenuPrivate::_q_actionTriggered()
 {
     Q_Q(QMenu);
     if (QAction *action = qobject_cast<QAction *>(q->sender())) {
-        QWeakPointer<QAction> actionGuard = action;
+        QPointer<QAction> actionGuard = action;
         emit q->triggered(action);
         if (!activationRecursionGuard && actionGuard) {
             //in case the action has not been activated by the mouse
index da49f43..c9c1951 100644 (file)
@@ -1043,7 +1043,7 @@ void tst_QThread::connectThreadFinishedSignalToObjectDeleteLaterSlot()
 {
     QThread thread;
     QObject *object = new QObject;
-    QWeakPointer<QObject> p = object;
+    QPointer<QObject> p = object;
     QVERIFY(!p.isNull());
     connect(&thread, SIGNAL(started()), &thread, SLOT(quit()), Qt::DirectConnection);
     connect(&thread, SIGNAL(finished()), object, SLOT(deleteLater()));
@@ -1128,7 +1128,7 @@ void tst_QThread::destroyFinishRace()
     for (int i = 0; i < 15; i++) {
         Thread *thr = new Thread;
         connect(thr, SIGNAL(finished()), thr, SLOT(deleteLater()));
-        QWeakPointer<QThread> weak(static_cast<QThread*>(thr));
+        QPointer<QThread> weak(static_cast<QThread*>(thr));
         thr->start();
         while (weak) {
             qApp->processEvents();
@@ -1284,7 +1284,7 @@ void tst_QThread::customEventDispatcher()
     // test that the ED has really been used
     QVERIFY(ed->visited);
 
-    QWeakPointer<DummyEventDispatcher> weak_ed(ed);
+    QPointer<DummyEventDispatcher> weak_ed(ed);
     QVERIFY(!weak_ed.isNull());
     thr.quit();
     // wait for thread to be stopped
index 997e15e..3adf286 100644 (file)
@@ -1189,7 +1189,7 @@ void tst_QTouchEvent::deleteInEventHandler()
                                Qt::NoModifier,
                                Qt::TouchPointReleased,
                                touchPoints);
-        QWeakPointer<QWidget> p;
+        QPointer<QWidget> p;
         bool res;
 
         touchBeginEvent.ignore();
@@ -1339,7 +1339,7 @@ void tst_QTouchEvent::deleteInRawEventTranslation()
     QPointF rightScreenPos = rightWidget->mapToGlobal(rightPos.toPoint());
     QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget);
 
-    QWeakPointer<QWidget> pl = leftWidget, pc = centerWidget, pr = rightWidget;
+    QPointer<QWidget> pl = leftWidget, pc = centerWidget, pr = rightWidget;
 
     QList<QTouchEvent::TouchPoint> rawTouchPoints;
     rawTouchPoints.append(QTouchEvent::TouchPoint(0));
index 81881fc..917337a 100644 (file)
@@ -300,7 +300,7 @@ public Q_SLOTS:
 // TODO rename to sendGestureSequence
 static void sendCustomGesture(CustomEvent *event, QObject *object, QGraphicsScene *scene = 0)
 {
-    QWeakPointer<QObject> receiver(object);
+    QPointer<QObject> receiver(object);
     for (int i = CustomGesture::SerialMaybeThreshold;
          i <= CustomGesture::SerialFinishedThreshold && receiver; ++i) {
         event->serial = i;
index 6540ab5..ebfec4d 100644 (file)
@@ -76,7 +76,7 @@ public:
 void tst_QSharedPointer_and_QWidget::weak_externalDelete()
 {
     QWidget *w = new QWidget;
-    QWeakPointer<QWidget> ptr = w;
+    QPointer<QWidget> ptr = w;
 
     QVERIFY(!ptr.isNull());
 
@@ -88,7 +88,7 @@ void tst_QSharedPointer_and_QWidget::weak_parentDelete()
 {
     QWidget *parent = new QWidget;
     QWidget *w = new QWidget(parent);
-    QWeakPointer<QWidget> ptr = w;
+    QPointer<QWidget> ptr = w;
 
     QVERIFY(!ptr.isNull());
 
@@ -100,7 +100,7 @@ void tst_QSharedPointer_and_QWidget::weak_parentDelete_setParent()
 {
     QWidget *parent = new QWidget;
     QWidget *w = new QWidget;
-    QWeakPointer<QWidget> ptr = w;
+    QPointer<QWidget> ptr = w;
     w->setParent(parent);
 
     QVERIFY(!ptr.isNull());
@@ -114,7 +114,7 @@ void tst_QSharedPointer_and_QWidget::weak_parentDelete_setParent()
 void tst_QSharedPointer_and_QWidget::strong_weak()
 {
     QSharedPointer<QWidget> ptr(new QWidget);
-    QWeakPointer<QWidget> weak = ptr.data();
+    QPointer<QWidget> weak = ptr.data();
     QWeakPointer<QWidget> weak2 = ptr;
 
     QVERIFY(!weak.isNull());
index 473c5e0..d5e8dce 100644 (file)
@@ -816,7 +816,7 @@ void tst_QMenu::deleteActionInTriggered()
     // should not crash
     QMenu m;
     QObject::connect(&m, SIGNAL(triggered(QAction*)), this, SLOT(deleteAction(QAction*)));
-    QWeakPointer<QAction> a = m.addAction("action");
+    QPointer<QAction> a = m.addAction("action");
     a.data()->trigger();
     QVERIFY(!a);
 }