I'm trying to use QtConcurrent::map to concurrently run a image conversion on each of the selected files that the user inputs to my app. For this I have a class that gets all the info about where the file will be stored and other stuff, and I have two methods for the conversion:
void ConvertThread::convert()
void ConvertThread::convertFileToPdf(const QString& file)
In the convert method, I set a QFuture<void> f = QtConcurrent::map(fileList, &ConvertThread::convertFileToPdf), where fileList is a QList<String>
I've been using code from Qt examples on how to do this and I think I got it right, but for some reason when I try to compile I'm getting this error:
/Library/Frameworks/QtCore.framework/Headers/qtconcurrentmapkernel.h: In member function 'bool QtConcurrent::MapKernel<Iterator, MapFunctor>::runIteration(Iterator, int, void*) [with Iterator = QList<QString>::iterator, MapFunctor = void (ConvertThread::*)(const QString&)]':
convertthread.cpp:39: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qtconcurrentmapkernel.h:73: error: must use '.*' or '->*' to call pointer-to-member function in '((QtConcurrent::MapKernel<QList<QString>::iterato r, void (ConvertThread::*)(const QString&)>*)this)->QtConcurrent::MapKernel<QList<QString>::iterato r, void (ConvertThread::*)(const QString&)>::map (...)'
make[1]: *** [debug/convertthread.o] Error 1
If anyone has experience with using QtConcurrent this way, I'd really appreciate some help here.
ps: I know some of the other code isn't connected yet
convertthread.cpp:
#include "convertthread.h"
#include <Magick++.h>
using namespace Magick;
void ConvertThread::enqueueFile(const QString& path) {
fileList << path;
}
void ConvertThread::convert() {
QFuture<void> f = QtConcurrent::map(fileList, &ConvertThread::convertFileToPdf);
converter->setFuture(f);
}
void ConvertThread::sendFinishedSignal() {
emit imageStatus();
}
void ConvertThread::setOutputDir(const QString& folder) {
destFolder = folder;
}
void ConvertThread::convertFileToPdf(const QString& file) {
QString fileName
= info
->baseName
();
outPath
= destFolder
+ QDir::separator() + fileName
+ ".pdf";
delete info;
Image *image = new Image();
try {
image->read(qPrintable(file));
image->magick("PDF");
image->write(qPrintable(outPath));
}
catch(Exception &error_) {
return;
}
delete image;
}
#include "convertthread.h"
#include <Magick++.h>
using namespace Magick;
void ConvertThread::enqueueFile(const QString& path) {
fileList << path;
}
void ConvertThread::convert() {
QFuture<void> f = QtConcurrent::map(fileList, &ConvertThread::convertFileToPdf);
converter->setFuture(f);
}
void ConvertThread::sendFinishedSignal() {
emit imageStatus();
}
void ConvertThread::setOutputDir(const QString& folder) {
destFolder = folder;
}
void ConvertThread::convertFileToPdf(const QString& file) {
QString outPath;
QFileInfo *info = new QFileInfo(file);
QString fileName = info->baseName();
outPath = destFolder + QDir::separator() + fileName + ".pdf";
delete info;
Image *image = new Image();
try {
image->read(qPrintable(file));
image->magick("PDF");
image->write(qPrintable(outPath));
}
catch(Exception &error_) {
return;
}
delete image;
}
To copy to clipboard, switch view to plain text mode
convertthread.h:
#ifndef CONVERTTHREAD_H
#define CONVERTTHREAD_H
#include <QObject>
#include <QtGui>
#include <QFuture>
#include <QFutureWatcher>
class ConvertThread
: public QObject{
Q_OBJECT
public:
ConvertThread() {
converter = new QFutureWatcher<void>(this);
connect(converter, SIGNAL(resultReadyAt(int)), SLOT(sendFinishedSignal()));
}
~ConvertThread() {
converter->cancel();
converter->waitForFinished();
}
void convert();
void enqueueFile(const QString& path);
void setOutputDir(const QString& folder);
void convertFileToPdf(const QString& file);
private:
QFutureWatcher<void> *converter;
QList<QString> fileList;
signals:
void imageStatus();
public slots:
void sendFinishedSignal();
};
#endif // CONVERTTHREAD_H
#ifndef CONVERTTHREAD_H
#define CONVERTTHREAD_H
#include <QObject>
#include <QtGui>
#include <QFuture>
#include <QFutureWatcher>
class ConvertThread : public QObject
{
Q_OBJECT
public:
ConvertThread() {
converter = new QFutureWatcher<void>(this);
connect(converter, SIGNAL(resultReadyAt(int)), SLOT(sendFinishedSignal()));
}
~ConvertThread() {
converter->cancel();
converter->waitForFinished();
}
void convert();
void enqueueFile(const QString& path);
void setOutputDir(const QString& folder);
void convertFileToPdf(const QString& file);
private:
QFutureWatcher<void> *converter;
QList<QString> fileList;
QString destFolder;
signals:
void imageStatus();
public slots:
void sendFinishedSignal();
};
#endif // CONVERTTHREAD_H
To copy to clipboard, switch view to plain text mode
Bookmarks