Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problems with Qt Concurrent mapped



  • I've been trying to create a simple image processing procedure where i have a list of images that needs to be written to the disk and trimmed so here is the code for this function
    @
    static int i=0;
    void writeRenderingImage(const QImage &q){

    QString path(QDir::currentPath().append("/moviePictures"));
    QString p(path);
    p.append(QString("/photo%1.png").arg(i++,5,10,QChar('0')));
    std::cout<<p.toStdString()<<"\n";
    q.save(p,"PNG",10);
    QString trimCommand("convert -trim ");
    trimCommand.append(p).append(" ").append(p);
    system&#40;trimCommand.toStdString(&#41;.c_str(&#41;&#41;;
    

    }
    @
    Since i have this function i have another function wich calls this procedure through the QtConcurrent::mapped utility
    @
    void GraphPrincipal::createMovieAction() {
    i=0;
    QString path(QDir::currentPath().append("/moviePictures"));
    QString command("rm -rf ");
    command.append(path).append("/*.png");
    system(command.toStdString().c_str());

    QProgressDialog dialog;
    dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount()));
    QFutureWatcher<void> futureWatcher;
    connect(&futureWatcher;, SIGNAL(finished()), &dialog;, SLOT(reset()));
    connect(&dialog;, SIGNAL(canceled()), &futureWatcher;, SLOT(cancel()));
    connect(&futureWatcher;, SIGNAL(progressRangeChanged(int, int)), &dialog;, SLOT(setRange(int, int)));
    connect(&futureWatcher;, SIGNAL(progressValueChanged(int)), &dialog;, SLOT(setValue(int)));
    

    //gsw->getRenderingImages() returns a QList<Qimage> object
    QFuture<void> qv=QtConcurrent::mapped(gsw->getRenderingImages(),writeRenderingImage);
    futureWatcher.setFuture(qv);
    dialog.exec();
    futureWatcher.waitForFinished();
    }
    @

    So When i try to run this code i get the following error.
    @
    /usr/include/qt4/QtCore/qtconcurrentmapkernel.h: In member function ‘bool QtConcurrent::MappedEachKernel<Iterator, MapFunctor>::runIteration(Iterator, int, QtConcurrent::MappedEachKernel<Iterator, MapFunctor>::T*) [with Iterator = QList<QImage>::const_iterator, MapFunctor = QtConcurrent::FunctionWrapper1<void, const QImage&>, QtConcurrent::MappedEachKernel<Iterator, MapFunctor>::T = void]’:
    In file included from /usr/include/qt4/QtCore/qtconcurrentfilterkernel.h:50:0,
    from /usr/include/qt4/QtCore/qtconcurrentfilter.h:49,
    from /usr/include/qt4/QtCore/QtCore:92,
    from /usr/include/qt4/QtGui/QtGui:3,
    from GraphPrincipal.h:10,
    from GraphPrincipal.cpp:7:
    GraphPrincipal.cpp:146:1: instantiated from here
    /usr/include/qt4/QtCore/qtconcurrentmapkernel.h:180:9: error: ‘QtConcurrent::MappedEachKernel<QList<QImage>::const_iterator<QImage>, QtConcurrent::FunctionWrapper1<void, const QImage&> >::T*’ is not a pointer-to-object type
    /usr/include/qt4/QtCore/qtconcurrentmapkernel.h: In member function ‘bool QtConcurrent::MappedEachKernel<Iterator, MapFunctor>::runIterations(Iterator, int, int, QtConcurrent::MappedEachKernel<Iterator, MapFunctor>::T*) [with Iterator = QList<QImage>::const_iterator, MapFunctor = QtConcurrent::FunctionWrapper1<void, const QImage&>, QtConcurrent::MappedEachKernel<Iterator, MapFunctor>::T = void]’:
    @

    Can some1 tell me what i'm doing wrong i've been reading all the docs i can but can't find no solution. if some1 could help, plz... do it so.



  • Ok as far as I understand the source code and the error provided by you the problem resides in this line of code:

    @
    QFuture<void> qv=QtConcurrent::mapped(gsw->getRenderingImages(),writeRenderingImage);
    @

    Its just a guess but I think the two parameters don't fit. As I understand from the compiler error the @gsw->getRenderingImages()@ returns an iterator of type @QList<QImage>::const_iterator<QImage>@ and writeRenderingImage() expects a const reference to an image.



  • i Thank u for your answer, but i solved it using pthread instead. I start one thread per picture to work on, than use pthread_join to track the progress of the work being done. Thanks for the answer anyway.


Log in to reply