Reputation: 1159
I have a class that I use to compress files into different formats. I'm trying to use QtConcurrent to run the compression in the background. With this I have two functions:
Issue is I'm getting issues with QtConcurrent not knowing which overloaded function to use. I read this stackoverflow which showed using static_cast to explicitly state which method to use. I'm getting stuck with the syntax though since my functions are class functions and not static methods. Can I even use static_cast for this considering these are not static methods?
How I'm calling run:
CompressFile compressor(&m_sysLog);
QVector<QString> files;
CompressFormat format((CompressFormat)pMsgCast->get_format());
QtConcurrent::run(&compressor, &CompressFile::compress, files, format);
Header for compression class
class CompressFile : public QObject
{
Q_OBJECT
public:
...
bool compress(QString strFileName, CompressFormat format);
bool compress(QVector<QString> strFileList, CompressFormat format);
...
}
If I remove one of the compress functions it compiles so I know I've narrowed my issue down to this.
FileCompressor.cpp:100:74: note: types ‘T (Class::)(Param1, Param2, Param3, Param4, Param5)const’ and ‘bool (CompressFile::)(QString, CompressFormat)’ have incompatible cv-qualifiers FileCompressor.cpp:100:74: note: could not resolve address from overloaded function ‘& CompressFile::compress’
Upvotes: 1
Views: 357
Reputation: 12909
As per the comment, you can use a static_cast
to disambiguate between the various overloads...
QtConcurrent::run(&compressor,
static_cast<bool(CompressFile::*)(QVector<QString>, CompressFormat)>(&CompressFile::compress),
files,
format);
Upvotes: 2