Monitoring multiple QProcess
in my GUI I want users to be able to select one or more files from an open dialog and to convert them (using an external application) into the application's native format... I was thinking to create a list of QProcess pointer's in order to manage this, but I wonder if there is an optimal solution to monitor some QProcess, maybe using the qt concurrent framework... anyone has already work on this ?
thanks a lot Giampaolo
I don't see any issue with just creating a bunch of QProcess instances. No need to use the concurrent framework for that. As long as you use the asynchronous API (that is: don't use the waitFor... methods), there is no problem creating multiple QProcess instances simultaniously. Note that, depending on the kind of work the processes must do, it might not be efficient to create multiple instances at the same time. For instance, if the work these converters do is IO bound, it might actually slow down the total process in some circumstances because all the convert processes have to wait for each other to read or write data, and the HD is less efficient if it has to move back and forth between files all the time.
I'm happy to see that I can efficently manage this without going deep into the qt concurrent API :D
to avoid processes to eat too many resources (eg if the user select 100 or more files) I was thinking to allow only a configured number of QProcess to run at the same time...
thank a lot for your time
Just put all files in a queue, and only allow a fixed number to run simultaniously at any point in time. It should be easy to create a simple manager class that keeps track of the number of processes you have fired off, and gets signalled when any of these finishes. You can use that finish signal to trigger the start of new processes, up to the number you allow and as long as you have unfinished tasks in your queue.