Rename QTimer::connectTo() to QTimer::callOnTimeout()
Some people suggested the later, so let's have a second look at it before it's too late. Although I was in favor of the former I'm now having second thoughts. connectTo() is meant to only be used in classes which have a clear dominant signal, but there are rare classes that have two (example: QAbstractButton::toggled, QAbstractButton::clicked). QAbstractButton::connectTo() would be ambiguous if we ever wanted to add these shorthand connects to QtWidgets Change-Id: I198ad3326d31dcf89b9c47a299124572ee7b11b3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
604c03f0b9
commit
179c88a1a9
@ -571,7 +571,7 @@ void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject *receiv
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template<typename Functor> QMetaObject::Connection connectTo(Functor functor, Qt::ConnectionType connectionType = Qt::AutoConnection)
|
||||
\fn template<typename Functor> QMetaObject::Connection callOnTimeout(Functor functor, Qt::ConnectionType connectionType = Qt::AutoConnection)
|
||||
\since 5.12
|
||||
\overload
|
||||
|
||||
@ -585,9 +585,9 @@ void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject *receiv
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template<typename Functor> QMetaObject::Connection connectTo(QObject *context, Functor functor, Qt::ConnectionType connectionType = Qt::AutoConnection)
|
||||
\fn template<typename Functor> QMetaObject::Connection callOnTimeout(QObject *context, Functor functor, Qt::ConnectionType connectionType = Qt::AutoConnection)
|
||||
\since 5.12
|
||||
\overload connectTo()
|
||||
\overload callOnTimeout()
|
||||
|
||||
Creates a connection from the timeout() signal to \a functor to be placed in a specific
|
||||
event loop of \a context, and returns a handle to the connection.
|
||||
@ -599,9 +599,9 @@ void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject *receiv
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template<typename PointerToMemberFunction> QMetaObject::Connection connectTo(QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType connectionType = Qt::AutoConnection)
|
||||
\fn template<typename PointerToMemberFunction> QMetaObject::Connection callOnTimeout(QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType connectionType = Qt::AutoConnection)
|
||||
\since 5.12
|
||||
\overload connectTo()
|
||||
\overload callOnTimeout()
|
||||
|
||||
Creates a connection from the timeout() signal to the \a method in the \a receiver object. Returns
|
||||
a handle to the connection.
|
||||
|
@ -97,11 +97,11 @@ public:
|
||||
template<typename Functor, int>
|
||||
static void singleShot(int msec, Qt::TimerType timerType, const QObject *context, Functor functor);
|
||||
template <typename Functor>
|
||||
QMetaObject::Connection connectTo(Functor slot, Qt::ConnectionType connectionType = Qt::AutoConnection);
|
||||
QMetaObject::Connection callOnTimeout(Functor slot, Qt::ConnectionType connectionType = Qt::AutoConnection);
|
||||
template <typename Functor>
|
||||
QMetaObject::Connection connectTo(const QObject *context, Functor slot, Qt::ConnectionType connectionType = Qt::AutoConnection);
|
||||
QMetaObject::Connection callOnTimeout(const QObject *context, Functor slot, Qt::ConnectionType connectionType = Qt::AutoConnection);
|
||||
template <typename PointerToMemberFunction>
|
||||
QMetaObject::Connection connectTo(const QObject *receiver, PointerToMemberFunction slot, Qt::ConnectionType connectionType = Qt::AutoConnection);
|
||||
QMetaObject::Connection callOnTimeout(const QObject *receiver, PointerToMemberFunction slot, Qt::ConnectionType connectionType = Qt::AutoConnection);
|
||||
#else
|
||||
// singleShot to a QObject slot
|
||||
template <typename Duration, typename Func1>
|
||||
@ -160,7 +160,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename ... Args>
|
||||
QMetaObject::Connection connectTo(Args && ...args)
|
||||
QMetaObject::Connection callOnTimeout(Args && ...args)
|
||||
{
|
||||
return QObject::connect(this, &QTimer::timeout, std::forward<Args>(args)... );
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ private slots:
|
||||
|
||||
void dontBlockEvents();
|
||||
void postedEventsShouldNotStarveTimers();
|
||||
void connectTo();
|
||||
void callOnTimeout();
|
||||
};
|
||||
|
||||
void tst_QTimer::zeroTimer()
|
||||
@ -979,7 +979,7 @@ void tst_QTimer::crossThreadSingleShotToFunctor()
|
||||
delete o;
|
||||
}
|
||||
|
||||
void tst_QTimer::connectTo()
|
||||
void tst_QTimer::callOnTimeout()
|
||||
{
|
||||
QTimer timer;
|
||||
QSignalSpy timeoutSpy(&timer, &QTimer::timeout);
|
||||
@ -989,9 +989,9 @@ void tst_QTimer::connectTo()
|
||||
auto context = new QObject();
|
||||
|
||||
int count = 0;
|
||||
timer.connectTo([&count] { count++; });
|
||||
QMetaObject::Connection connection = timer.connectTo(context, [&count] { count++; });
|
||||
timer.connectTo(&timer, &QTimer::stop);
|
||||
timer.callOnTimeout([&count] { count++; });
|
||||
QMetaObject::Connection connection = timer.callOnTimeout(context, [&count] { count++; });
|
||||
timer.callOnTimeout(&timer, &QTimer::stop);
|
||||
|
||||
|
||||
QTest::qWait(100);
|
||||
|
Loading…
Reference in New Issue
Block a user