Add a few std::move in functions accepting slots

This allows the use of move-only function objects

Task-number: QTBUG-60339
Change-Id: If3595fca338cf7f3039eb566cc02e4e73cd04c86
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Olivier Goffart 2017-04-22 13:21:28 +02:00 committed by Olivier Goffart (Woboq GmbH)
parent a6c091c2d1
commit 9d918495ee
5 changed files with 21 additions and 14 deletions

View File

@ -122,14 +122,14 @@ public:
!std::is_same<const char*, Func1>::value, void>::type
singleShot(Duration interval, Func1 slot)
{
singleShot(interval, defaultTypeFor(interval), nullptr, slot);
singleShot(interval, defaultTypeFor(interval), nullptr, std::move(slot));
}
template <typename Duration, typename Func1>
static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction &&
!std::is_same<const char*, Func1>::value, void>::type
singleShot(Duration interval, Qt::TimerType timerType, Func1 slot)
{
singleShot(interval, timerType, nullptr, slot);
singleShot(interval, timerType, nullptr, std::move(slot));
}
// singleShot to a functor or function pointer (with context)
template <typename Duration, typename Func1>
@ -137,7 +137,7 @@ public:
!std::is_same<const char*, Func1>::value, void>::type
singleShot(Duration interval, QObject *context, Func1 slot)
{
singleShot(interval, defaultTypeFor(interval), context, slot);
singleShot(interval, defaultTypeFor(interval), context, std::move(slot));
}
template <typename Duration, typename Func1>
static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction &&
@ -150,7 +150,7 @@ public:
singleShotImpl(interval, timerType, context,
new QtPrivate::QFunctorSlotObject<Func1, 0,
typename QtPrivate::List_Left<void, 0>::Value, void>(slot));
typename QtPrivate::List_Left<void, 0>::Value, void>(std::move(slot)));
}
#endif

View File

@ -125,7 +125,7 @@ public:
!std::is_same<const char *, Func>::value, int>::type
lookupHost(const QString &name, Func slot)
{
return lookupHost(name, nullptr, slot);
return lookupHost(name, nullptr, std::move(slot));
}
// lookupHost to a functor or function pointer (with context)
@ -141,7 +141,7 @@ public:
auto slotObj = new QtPrivate::QFunctorSlotObject<Func1, 1,
typename QtPrivate::List<QHostInfo>,
void>(slot);
void>(std::move(slot));
return lookupHostImpl(name, context, slotObj);
}
#endif // Q_QDOC

View File

@ -108,7 +108,7 @@ public:
#else
result->setShortcut(shortcut);
#endif
connect(result, &QAction::triggered, object, slot);
connect(result, &QAction::triggered, object, std::move(slot));
return result;
}
// addAction(QString): Connect to a functor or function pointer (without context)
@ -121,7 +121,7 @@ public:
#else
result->setShortcut(shortcut);
#endif
connect(result, &QAction::triggered, slot);
connect(result, &QAction::triggered, std::move(slot));
return result;
}
// addAction(QIcon, QString): Connect to a QObject slot / functor or function pointer (with context)
@ -136,7 +136,7 @@ public:
#else
result->setShortcut(shortcut);
#endif
connect(result, &QAction::triggered, object, slot);
connect(result, &QAction::triggered, object, std::move(slot));
return result;
}
// addAction(QIcon, QString): Connect to a functor or function pointer (without context)
@ -149,7 +149,7 @@ public:
#else
result->setShortcut(shortcut);
#endif
connect(result, &QAction::triggered, slot);
connect(result, &QAction::triggered, std::move(slot));
return result;
}
#endif // !Q_QDOC

View File

@ -121,7 +121,7 @@ public:
addAction(const QString &text, const Obj *object, Func1 slot)
{
QAction *result = addAction(text);
connect(result, &QAction::triggered, object, slot);
connect(result, &QAction::triggered, object, std::move(slot));
return result;
}
// addAction(QString): Connect to a functor or function pointer (without context)
@ -139,7 +139,7 @@ public:
addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot)
{
QAction *result = addAction(actionIcon, text);
connect(result, &QAction::triggered, object, slot);
connect(result, &QAction::triggered, object, std::move(slot));
return result;
}
// addAction(QIcon, QString): Connect to a functor or function pointer (without context)

View File

@ -834,7 +834,6 @@ void tst_QTimer::singleShotToFunctors()
QTest::qWait(800);
QCOMPARE(count, 2);
#if defined(Q_COMPILER_LAMBDA)
QTimer::singleShot(0, [&count] { ++count; });
QCoreApplication::processEvents();
QCOMPARE(count, 3);
@ -853,7 +852,15 @@ void tst_QTimer::singleShotToFunctors()
thread.quit();
thread.wait();
#endif
struct MoveOnly : CountedStruct {
Q_DISABLE_COPY(MoveOnly);
MoveOnly(MoveOnly &&o) : CountedStruct(std::move(o)) {};
MoveOnly(int *c) : CountedStruct(c) {}
};
QTimer::singleShot(0, MoveOnly(&count));
QCoreApplication::processEvents();
QCOMPARE(count, 5);
_e.reset();
_t = Q_NULLPTR;