0

I have a function which is named RunProcess. I want to use it in a concurrent process to make GUI responsiveness, So I tried to run my function in concurrent process but It does not recognize the function. here is my class

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "gdal_priv.h"
#include "cpl_conv.h" // for CPLMalloc()
#include "ogr_srs_api.h"
#include <QDir>
#include <QFile>
#include <QDebug>
#include <iostream>
#include <cstring>
#include <string>
#include <QFileDialog>
#include <QThread>
#include <QtConcurrent/QtConcurrent>


using namespace QtConcurrent;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{


    ui->setupUi(this);
    connect(ui->startProcess, SIGNAL (released()), this, SLOT (StartProcess()));

}




void MainWindow::StartProcess(){


    sendinfo("Starting Process... Note that the input images <b>must<\b> be in ESPG:3857.");

    QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
                                                    "/home",
                                                    QFileDialog::ShowDirsOnly
                                                    | QFileDialog::DontResolveSymlinks);


    if(dir==""){
        sendwarning("nothing is selected.");
            return;
    }
    sendinfo("The selected folder is: "+dir);


    QFuture<void> f1 = run(RunProcess,dir);
    f1.waitForFinished();

}


void MainWindow::RunProcess( QString dir){

    if(dir==""){
        sendwarning("nothing is selected.");
            return;
    }
    sendinfo("The selected folder is: "+dir);
    QString path(dir);
    QDir directory(path);

    if(directory.exists()){
        ....
    }else{

        //directory does not exist
        senderror("directory does not exist");

    }

}

here is my header

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "gdal_priv.h"
#include "ogr_spatialref.h"
#include "gdal_utils_priv.h"
#include "cpl_error.h"
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    void RunProcess();

    ~MainWindow();
public slots:
    void StartProcess();
private:
    Ui::MainWindow *ui;
    void senderror(QString msg);
    void sendinfo(QString msg);
    void sendwarning(QString msg);
    void gettext(QString msg,QString color);
};

#endif // MAINWINDOW_H

The above code returns

 mainwindow.cpp:180: error: invalid use of non-static member function ‘void MainWindow::RunProcess()’
     QFuture<void> f1 = run(RunProcess,dir);
                                         ^

Can you please help me find my mistake? thanks

Majid Hojati
  • 1,740
  • 4
  • 29
  • 61
  • _"It does not recognise the function"_ Yes, it does. How could it tell you that you used the wrong syntax for that function, if it did not recognise it? – underscore_d Dec 13 '17 at 11:52
  • @underscore_d Hi, thanks, so where am I doing wrong? – Majid Hojati Dec 13 '17 at 12:09
  • Did you look at the linked duplicate at all? – underscore_d Dec 13 '17 at 12:12
  • @underscore_d yes but could not understand my mistake – Majid Hojati Dec 13 '17 at 12:19
  • Prepend `&YourClassName::` to the member function name and try that. – underscore_d Dec 13 '17 at 12:20
  • @underscore_d I tried but it gives me the same error:= invalid use of non-static member function ‘void MainWindow::RunProcess()’ QFuture f1 = run(MainWindow::RunProcess,dir); ^ – Majid Hojati Dec 13 '17 at 12:22
  • Right, I think, as in the dupe, you need to also pass the instance whose member function you want to be called, as the first argument followed by the pointer-to-member. Reading the documentation would make this clear. Here's a better duplicate: [is it possible to use QtConcurrent::run() with a function member of a class](https://stackoverflow.com/questions/2152355/is-it-possible-to-use-qtconcurrentrun-with-a-function-member-of-a-class) – underscore_d Dec 13 '17 at 12:26
  • @underscore_d none of them worked. – Majid Hojati Dec 14 '17 at 13:46

0 Answers0