I am working on Qt application. There I would like to have worker thread doing some activities in background and I would like main thread to control it, restarting worker thread if it dies for some reason. I have seen finished() signal emitted by the thread so I guess I could connect slot to it.
Is that the recommended way? If not, how could I achieve that?
If I use finished() signal how can I know difference between normal termination and error?
Thanks and regards
If you want to know whether you had an error or you had the process finished, simply create two signals, not one, and two slots, not one.
In the Qt documentation you have an example there, with a connection to handle the result:
you're here connecting the signal
resultReadywith whatever method that handles the result. You create another one exactly like this, but with an error signal, and an error handler.Of course, another option is to simply pass a parameter with your signals/slots. It's a function call, and if you put some
enumwith that for the status or someint, that'll do.