PDA

View Full Version : Background process execution in Qt



locke
11th March 2010, 15:37
Hi everyone,

I would like to know if it is possible to launch a function or a process in backgroud mode.

The idea is, that I have a function that takes a long time to finish, because It manages a big amount of data. And then, I don´t want to stop the program during its execution. So the idea is to run this function at the beginning of the program execution in background mode. Meanwhile, the user could interact with the application whitout knowing that there is another process running within this application.

It is possible?

Thanks!!

TMan
11th March 2010, 15:59
Did you take a look at QThread and QProcess?

locke
11th March 2010, 16:12
It seems that you can execute external applications with QProcess, but Im not sure about methods of a class within your application

Lykurg
11th March 2010, 16:16
If it is only a function you can look at QtConcurrentRun.

locke
11th March 2010, 16:54
Hi, QtConcurrentRun sounds very good, but I try:

I call the function below from a method of the class MainWindow, so the object I provide in the fucntion si the "this" pointer.



//original function is: bool MainWindow::myFunction(QString s);

QString dir = "Example";

QFuture<bool> future = QtConcurrent::run(this, &MainWindow::myFunction, dir);

bool result = future.result();


But it locks the program, and I need to finish it. Any idea??

Thanks