summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qrunnable.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2023-03-28 10:38:25 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2023-04-04 01:05:47 +0200
commitc080d1e64d6e7c29bedfef48676f753c8bc0259c (patch)
tree801425a7e164e3eb62b370c592357bd37825c7d6 /src/corelib/thread/qrunnable.cpp
parent5c4a94ba85f0bed9633c385455685ba364a72540 (diff)
Create any callable using QRunnable::create
The overhead of making new custom classes appears to be less than constructing a generic std::function. [ChangeLog][QtCore][QRunnable] QRunnable::create can now take non-copyable functions as argument. Task-number: QTBUG-112302 Change-Id: Ied870f13ca6c7eaa14ed6eff9c4e676c7b73881c Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/thread/qrunnable.cpp')
-rw-r--r--src/corelib/thread/qrunnable.cpp22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/corelib/thread/qrunnable.cpp b/src/corelib/thread/qrunnable.cpp
index 5bb354cbb1..718802010a 100644
--- a/src/corelib/thread/qrunnable.cpp
+++ b/src/corelib/thread/qrunnable.cpp
@@ -77,31 +77,17 @@ QRunnable::~QRunnable()
\sa autoDelete(), QThreadPool
*/
-class FunctionRunnable : public QRunnable
-{
- std::function<void()> m_functionToRun;
-public:
- FunctionRunnable(std::function<void()> functionToRun) : m_functionToRun(std::move(functionToRun))
- {
- }
- void run() override
- {
- m_functionToRun();
- }
-};
-
/*!
+ \fn template<typename Callable> QRunnable *QRunnable::create(Callable &&callableToRun);
\since 5.15
- Creates a QRunnable that calls \a functionToRun in run().
+ Creates a QRunnable that calls \a callableToRun in run().
Auto-deletion is enabled by default.
+ \note In Qt versions prior to 6.6, this method took copyable functions only.
+
\sa run(), autoDelete()
*/
-QRunnable *QRunnable::create(std::function<void()> functionToRun)
-{
- return new FunctionRunnable(std::move(functionToRun));
-}
QT_END_NAMESPACE