Solved How to launch multiple processes but not create seperate slots for each process instance
-
I want to run a few processes at the same time and I want to add each new instance to a list of processes but I want each process to update it's own progress bar. I have a list of progress bars also, and it has the same index numbers as the corresponding process instance.
However I am not sure how to pass that index number to the slots.
@ void MainWindow::runAllProcesses()
{
.....
process = new QProcess(this);
connect( process, SIGNAL(started()), this, SLOT(processStarted()));
connect( process, SIGNAL(readyRead()), this, SLOT(processRead()));
connect( timer, SIGNAL( timeout()), this, SLOT(timesup()));
@Ideally, if I could have a parameter to processStarted( instanceNumber) would be best but readyRead() and processRead() don't take any parameters.
-
You can use "QSignalMapper":http://qt-project.org/doc/qt-5/qsignalmapper.html#details to pass parameters through the signals that do not support parameters.
-
If you are using Qt5, you could probably use the new signal/slot-syntax in conjunction with a lambda expression_ _ (needs C++11).
Something similar to this:
@process = new QProcess(this);
connect(process, &QProcess::started, this, this
{
processStarted();//you may pass a parameter or just do necessary things right here
});@There is a very helpful "article":http://qt-project.org/wiki/New_Signal_Slot_Syntax on these things.