PDA

View Full Version : Problem using QtConcurrent with members fuctions



Hogwarts
5th October 2012, 17:33
Hello every one!
I'm using QtConcurrent to load a file in other thread:




struct tipoRegistro {
qint16 val1;
qint16 val2 ;
qint16 val3;
};

tipoRegistro MainWindow::readFileStepByStep()
{
file.read(reinterpret_cast<char*> (&reg),sizeof(tipoRegistro));
return reg;
}

void MainWindow::qtConcurrentTest()
{
QVector<tipoRegistro> vector;
tipoRegistro treg;
treg.val1 = -1;
treg.val2 = -1;
treg.val3 = -1;
for(int i = 0; i < num_muestras_canal; i++)
vector.append(treg);

QProgressDialog dialog;
dialog.setLabelText(QString("Cargando archivo ECG"));

QFutureWatcher<void> futureWatcher;
QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset()));
QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int)));
QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));

futureWatcher.setFuture(QtConcurrent::mapped(vecto r,readFileStepByStep));

dialog.exec();

futureWatcher.waitForFinished();
}

I get the fallowing error:


../ECGReader/mainwindow.cpp: In member function 'void MainWindow::qtConcurrentTest()':
../ECGReader/mainwindow.cpp:264:75: error: no matching function for call to 'mapped(QVector<tipoRegistro>&, <unresolved overloaded function type>)'
../ECGReader/mainwindow.cpp:264:75: note: candidates are:
/usr/include/qt4/QtCore/qtconcurrentmap.h:181:74: note: QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> QtConcurrent::mapped(const Sequence&, MapFunctor) [with Sequence = QVector<tipoRegistro>, MapFunctor = tipoRegistro (MainWindow::*)(), typename QtPrivate::MapResultType<void, MapFunctor>::ResultType = void]
/usr/include/qt4/QtCore/qtconcurrentmap.h:181:74: note: no known conversion for argument 2 from '<unresolved overloaded function type>' to 'tipoRegistro (MainWindow::*)()'
/usr/include/qt4/QtCore/qtconcurrentmap.h:188:74: note: template<class Iterator, class MapFunctor> QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> QtConcurrent::mapped(Iterator, Iterator, MapFunctor)

I think the problem can be using members fuction, but i tried modifying the line tis way:


futureWatcher.setFuture(QtConcurrent::mapped(vecto r, &MainWindow::readFileStepByStep)); but I keep getting errors

If anyone can help...thanks in advanced.
Regards.

pd: Sorry my english

amleto
5th October 2012, 19:08
If you had searched you would have found this:
http://www.qtcentre.org/threads/32288-QtConcurrent-run()-with-function-member

It suggests lookling here... http://doc.qt.digia.com/4.6/qtconcurrentrun.html