summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qrunnable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread/qrunnable.cpp')
-rw-r--r--src/corelib/thread/qrunnable.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/corelib/thread/qrunnable.cpp b/src/corelib/thread/qrunnable.cpp
index 5bb354cbb1..f9d69ed5cb 100644
--- a/src/corelib/thread/qrunnable.cpp
+++ b/src/corelib/thread/qrunnable.cpp
@@ -3,6 +3,8 @@
#include "qrunnable.h"
+#include <QtCore/qlogging.h>
+
QT_BEGIN_NAMESPACE
QRunnable::~QRunnable()
@@ -10,6 +12,27 @@ QRunnable::~QRunnable()
}
/*!
+ \internal
+ Prints a warning and returns nullptr.
+*/
+QRunnable *QRunnable::warnNullCallable()
+{
+ qWarning("Trying to create null QRunnable. This may stop working.");
+ return nullptr;
+}
+
+
+QRunnable::QGenericRunnable::~QGenericRunnable()
+{
+ runHelper->destroy();
+}
+
+void QRunnable::QGenericRunnable::run()
+{
+ runHelper->run();
+}
+
+/*!
\class QRunnable
\inmodule QtCore
\since 4.4
@@ -77,31 +100,20 @@ 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::if_callable<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 This function participates in overload resolution only if \c Callable
+ is a function or function object which can be called with zero arguments.
+
+ \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