Making a call to AVRDUDE script from within my C++ app, but need to know when process complete

I am writing an application in C++ (Qt creator application), and I have embedded a call to an external AVRDUDE script. The script executes perfectly, however control is returned to the spawning C++ program immediately after the call, and NOT upon completion. here is the function call

void MainWindow::call_AVRDUDE_read() {
QProcess CommandPrompt;
QStringList Arguments;
Arguments <<"C/ avrdude -c arduino -P com3 -b 115200 -p ATmega328P -e -U eeprom:r:fromEEPROM.bin:r";
CommandPrompt.startDetached("cmd",Arguments);

The script runs fine and does exactly as it should, but reading the EEPROM of course takes a few seconds to execute the task. In the meantime, control has been returned to the c++ program which spawned the AVRDUDE script and is off trying to evaluate the contents of "fromEEPROM.bin" prior to its arrival. I know this to be true as I have placed a breakpoint in the code shortly after the call to the AVRDUDE read function. The breakpoint is hit immediately after the call to the above script.

So the crux of the problem is how to suspend execution of the calling code while the AVRDUDE script is in process. Then, when the EEPROM read is completed, return control to the host process so it can proceed with its process.

One last thing: I did try inserting "CommandPrompt.waitForFinished();" in the above function at the tail end, but it did nothing. Any thoughts?

As the name imply, startDetached will start and detach the process.(see QProcess Class | Qt Core 5.15.12)

So if you want synchronous operation, you don’t want to detach it and just use start (QProcess Class | Qt Core 5.15.12) and monitor for completion and get exit code etc

PS: this is not an avrdude question, moved your post to a more suitable location. I would say the best place to discuss this would be in a Qt creator forum

Thanks. I wasn't really sure where to post the question, but thought avrdude might be involved. I will remove the post and go to Qt Forum. I appreciate the lead...

You can leave the post here - not an issue, just that the readers here might not be very sharp with your coding environment so you won’t get much detailed input/ideas (although in this case I believe using start() would get you where you want to be)

Have fun

1 Like