Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to launch multiple processes but not create seperate slots for each process instance
ki John last edited by
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.
andreyc last edited by
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.
thEClaw last edited by
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.