From f1f4fd16fdd219701261d305e6d9f7abcb8bf4a9 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Tue, 22 Dec 2020 13:06:25 +0100 Subject: Document that QtConcurrent::run doesn't support overloaded functions After improving QtConcurrent::run() to use parameter packs for the arguments (see c977e74afd18afff8729070f631e6b7a3f2887f5), calling overloaded functions is ambiguous. Updated the porting guide and the documentation to mention this and describe possible workarounds. Task-number: QTBUG-89648 Pick-to: 6.0 Change-Id: I4c1f996ae67bce8c13cc1f99f54240295db6ae1d Reviewed-by: Jarek Kobus --- src/concurrent/qtconcurrentrun.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/concurrent/qtconcurrentrun.cpp') diff --git a/src/concurrent/qtconcurrentrun.cpp b/src/concurrent/qtconcurrentrun.cpp index 978bc8cd8dc..8347440b66e 100644 --- a/src/concurrent/qtconcurrentrun.cpp +++ b/src/concurrent/qtconcurrentrun.cpp @@ -89,6 +89,26 @@ the function. Changes made to the arguments after calling QtConcurrent::run() are \e not visible to the thread. + Note that QtConcurrent::run does not support calling overloaded functions + directly. For example, the code below won't compile: + +//! [run-with-overload-calls] + \snippet code/src_concurrent_qtconcurrentrun.cpp 15 + + The easiest workaround is to call the overloaded function through lambda: + + \snippet code/src_concurrent_qtconcurrentrun.cpp 16 + + Or you can tell the compiler which overload to choose by using a + \c static_cast: + + \snippet code/src_concurrent_qtconcurrentrun.cpp 17 + + Or qOverload: + + \snippet code/src_concurrent_qtconcurrentrun.cpp 18 +//! [run-with-overload-calls] + \section2 Returning Values from the Function Any return value from the function is available via QFuture: -- cgit v1.2.3