Just launch a function and do not append to it?
I am not sure you got me....
What I need is to just launch a function like it was a separate program.
For example, if a timer was connected to a slot like this:
Code:
void slot_1(){
while(1){
sleep(10);
}
}
the program would stack! I don't want it to 'stack'. I want to go forward even if such a function was called. Is this possible?
To be more realistic, I have a system command that reaches some files from the internet, and it may be late sometime and make my program unresponsive to clicks etc because of this....
PS: I though that QTimer::SingleShot was for that job but it does append to the slot unfortunately, so, after all, what's the difference between
Code:
QTimer::singleShot(0,
this,
SLOT(function
()));
and
Thanks for any answers!
Re: Just launch a function and do not append to it?
I think what you need is to run the function in separate thread. Search for examples on Qt Centre wiki or threads on forum.
Re: Just launch a function and do not append to it?
Hm, thank google wasn't very helpful....
Should I use QThread or QObject? This wasn't clear too...
Do I have to create my own classes? Can I avoid this? I need something simple, like:
Code:
object.setFunction(MainWindow::MyFunction_that_I_want_to_be_launched());
object.run
//more code here that will be executed without waiting the MyFunction_that_I_want_to_be_launched() to finish running
I don't know what are they talking about producers and consumers....:confused:
Re: Just launch a function and do not append to it?
If you want to run only one function, take a look at QtConcurrent module and QtConcurrent::run method.
Quote:
I don't know what are they talking about producers and consumers....
Because it's a standard example used to explain multithreading concepts.
Re: Just launch a function and do not append to it?
Yeah! This did the trick man! Thanks :)