I have a working, finished application which uses multiple boost threads and works fine with a command line interface.
I have packaged this program with a "wrapper" class so that I can run the functions within the program from a Qt Main Window.
For example:
netWrap.getImgs(ui->sampleNameEdit->text().toStdString());
This gets images from the network program with the parameter sampleName from a textbox and is called from a slot triggered by a pushbutton.
This all works fine, however, some functions, such as the one above, can take about 20 seconds to run and this hangs the GUI. I'd like it to not hang the GUI.
The obvious choice is to use a QThread
, but I don't want to add extra classes to my program as this is only supposed to be a simple front end. Is there a way that I can run this function in a thread and wait for a termination signal without hanging the GUI?
EDIT: QFutures:
QFuture<int> run = QtConcurrent::run(&(netWrap.getImgs), ui->sampleNameEdit->text().toStdString());
This produces 4 errors, the most relevant are probably:
error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say '&networkWrapper::getImgs' [-fpermissive]
QFuture<int> run = QtConcurrent::run(&(netWrap.getImgs), ui->sampleNameEdit->text().toStdString());
and:
error: no matching function for call to 'run(int (networkWrapper::*)(std::string), std::string)'
QFuture<int> run = QtConcurrent::run(&(netWrap.getImgs), ui->sampleNameEdit->text().toStdString());