1

I have code, where I need to implement passing pointer to a function with an argument, like in code below, but it doen't seems to be possible.

bool StudentAbsenceTableApp::loadFile(const QString &fileName)
{
    fw.moveToThread(this->thread());
    fw.setParent(this);
    //I need: &(StudentAbsenceTableApp::experimentFunction(fileName)
    QFuture<bool> future =  QtConcurrent::run(this, &StudentAbsenceTableApp::experimentFunction);
    fw.setFuture(future);

    progressBar->show();
}
// I need: experimentFunction(const QString& fileName)
bool StudentAbsenceTableApp::experimentFunction()
{
    QString fileName = "/media/bsuir/data.xml";
    XMLParser *xmlParser = new XMLParser(model);

    xmlParser->read(fileName);
    setCurrentFileName(fileName);
    statusBar()->showMessage(tr("Файл загружен"), 2000);
    documentModified = false;

    return true;
}

But there are no ways, I could find.

3
  • have you tried using a simple signal and slot based call? Commented Jun 8, 2017 at 22:31
  • If you are able to modify the definition of the class, you can modify the declaration of the member function expermientFunction(). If you are not able to modify the class definition, then you are right. You are out of luck there. Commented Jun 8, 2017 at 22:32
  • 1
    Just simply QtConcurrent::run(this, &StudentAbsenceTableApp::experimentFunction, fileName) Commented Jun 8, 2017 at 22:43

1 Answer 1

1

QtConcurrent::run Supports passing arguments to the function.

QFuture<bool> future =  QtConcurrent::run(this, &StudentAbsenceTableApp::experimentFunction, fileName);

Refer the documentation : http://doc.qt.io/qt-4.8/qtconcurrentrun.html#passing-arguments-to-the-function

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.