Make QTimer::singleShot take a pointer-to-const QObject
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Thu, 13 Sep 2012 18:23:10 +0000 (19:23 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 19 Sep 2012 14:13:39 +0000 (16:13 +0200)
The obvious idea is that a connect() happens behind the scenes.
As QObject::connect takes a pointer-to-const, singleShot should
do that as well.

Change-Id: I36433c723441294b2088b23f0c37724ab43d9503
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
src/corelib/kernel/qtimer.cpp
src/corelib/kernel/qtimer.h

index 6c89e52..af1d796 100644 (file)
@@ -257,14 +257,14 @@ class QSingleShotTimer : public QObject
     int timerId;
 public:
     ~QSingleShotTimer();
-    QSingleShotTimer(int msec, Qt::TimerType timerType, QObject *r, const char * m);
+    QSingleShotTimer(int msec, Qt::TimerType timerType, const QObject *r, const char * m);
 Q_SIGNALS:
     void timeout();
 protected:
     void timerEvent(QTimerEvent *);
 };
 
-QSingleShotTimer::QSingleShotTimer(int msec, Qt::TimerType timerType, QObject *receiver, const char *member)
+QSingleShotTimer::QSingleShotTimer(int msec, Qt::TimerType timerType, const QObject *receiver, const char *member)
     : QObject(QAbstractEventDispatcher::instance())
 {
     connect(this, SIGNAL(timeout()), receiver, member);
@@ -312,7 +312,7 @@ void QSingleShotTimer::timerEvent(QTimerEvent *)
     \sa start()
 */
 
-void QTimer::singleShot(int msec, QObject *receiver, const char *member)
+void QTimer::singleShot(int msec, const QObject *receiver, const char *member)
 {
     // coarse timers are worst in their first firing
     // so we prefer a high precision timer for something that happens only once
@@ -334,7 +334,7 @@ void QTimer::singleShot(int msec, QObject *receiver, const char *member)
 
     \sa start()
 */
-void QTimer::singleShot(int msec, Qt::TimerType timerType, QObject *receiver, const char *member)
+void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject *receiver, const char *member)
 {
     if (receiver && member) {
         if (msec == 0) {
@@ -345,7 +345,7 @@ void QTimer::singleShot(int msec, Qt::TimerType timerType, QObject *receiver, co
                 return;
             }
             QByteArray methodName(member+1, bracketPosition - 1 - member); // extract method name
-            QMetaObject::invokeMethod(receiver, methodName.constData(), Qt::QueuedConnection);
+            QMetaObject::invokeMethod(const_cast<QObject *>(receiver), methodName.constData(), Qt::QueuedConnection);
             return;
         }
         (void) new QSingleShotTimer(msec, timerType, receiver, member);
index fa68676..593f857 100644 (file)
@@ -78,8 +78,8 @@ public:
     inline void setSingleShot(bool singleShot);
     inline bool isSingleShot() const { return single; }
 
-    static void singleShot(int msec, QObject *receiver, const char *member);
-    static void singleShot(int msec, Qt::TimerType timerType, QObject *receiver, const char *member);
+    static void singleShot(int msec, const QObject *receiver, const char *member);
+    static void singleShot(int msec, Qt::TimerType timerType, const QObject *receiver, const char *member);
 
 public Q_SLOTS:
     void start(int msec);