Reputation: 93
I'm trying to call QImage::fill() asynchronously using the QtConcurrent module. The invert pixels example works fine but a similar syntax for the fill method does not:
#include <QApplication>
#include <QImage>
#include <QFuture>
#include <QtConcurrent/QtConcurrentRun>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QImage image(1920, 1080, QImage::Format_ARGB32_Premultiplied);
QFuture<void> future = QtConcurrent::run(&image, &QImage::fill, Qt::transparent); // ko
//QFuture<void> future = QtConcurrent::run(&image, &QImage::invertPixels, QImage::InvertRgba); // ok
future.waitForFinished();
return app.exec();
}
Compilation fails with the following error:
error: no matching function for call to ‘run(QImage*, <unresolved overloaded function type>, Qt::GlobalColor)’
10 | QFuture<void> future = QtConcurrent::run(&img, &QImage::fill, Qt::transparent); // ko
| ^
In file included from /usr/include/x86_64-linux-gnu/qt5/QtConcurrent/QtConcurrentRun:1,
from /home/romain/code/qt/main.cc:4:
/usr/include/x86_64-linux-gnu/qt5/QtConcurrent/qtconcurrentrun.h:72:12: note: candidate: ‘template<class T> QFuture<T> QtConcurrent::run(T (*)())’
72 | QFuture<T> run(T (*functionPointer)())
| ^~~
/usr/include/x86_64-linux-gnu/qt5/QtConcurrent/qtconcurrentrun.h:72:12: note: template argument deduction/substitution failed:
/home/romain/code/qt/main.cc:10:80: note: mismatched types ‘T()’ and ‘QImage’
10 | QFuture<void> future = QtConcurrent::run(&img, &QImage::fill, Qt::transparent); // ko
| ^
Is it possible to help the compiler by marking some template types explicitly?
Upvotes: 1
Views: 298
Reputation: 12899
The problem is that QImage::fill
has multiple overloads. You need to disambiguate using either static_cast
...
QFuture<void> future = QtConcurrent::run(&image, static_cast<void(QImage::*)(Qt::GlobalColor)>(&QImage::fill), Qt::transparent);
or (since this is Qt
) QOverload
...
QFuture<void> future = QtConcurrent::run(&image, qOverload<Qt::GlobalColor>(&QImage::fill), Qt::transparent);
Upvotes: 2