我有代码,我需要在其中实现将指针传递给带有参数的函数,如下面的代码所示,但这似乎是不可能的。
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;
}
但是没有办法,我能找到。
最佳答案
QtConcurrent::run 支持传递参数给函数。
QFuture<bool> future = QtConcurrent::run(this, &StudentAbsenceTableApp::experimentFunction, fileName);
引用文档:http://doc.qt.io/qt-4.8/qtconcurrentrun.html#passing-arguments-to-the-function
关于c++ - 将指针传递给以参数作为参数的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44446548/