Solved loop for not waiting the end of process
-
@filipdns I will try to change the process to . in place of file name, I will see if it work but I doubt because in the .bat, I have to have for %%f in to make it convert all files, that why I pass trough loop for or foreach but without success
-
@SGaist Hi SGaist, building with argument was my first attempt, but I have exactly the same result
-
here how was my first code
program=QDir::toNativeSeparators("//DGS1109N007/Echanges_SAA/Affichage/Display/imagmagick/magick.exe ") QStringList arguments; arguments<< "convert -density 300 -trim "<<QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Messages/")+filename<<" -quality 100 "<<QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Display/Messages/output.jpg"); myProcess.start(program,arguments);
-
@filipdns said in loop for not waiting the end of process:
arguments<< "convert -density 300 -trim "<<QDir::toNativeSeparators(""//DGS1109N007/Echanges_SAA/Affichage/Messages/")+filename<<" -quality 100 "<<QDir::toNativeSeparators(""//DGS1109N007/Echanges_SAA/Affichage/Display/Messages/output.jpg");
This is wrong. EVERY parameter needs to be an element in parameter list. Like:
arguments<< "convert" << "-density" << "300" << "-trim "<<QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Messages/")+filename << "-quality" << "100 "<<QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Display/Messages/output.jpg");
-
@jsulm Hello, I try that but it's not working.
I solve my issue with:
program=QDir::toNativeSeparators("//DGS1109N007/Echanges_SAA/Affichage/Display/imagmagick/magick ")+ "convert -density 300 -trim "+ QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Messages/"+filename)+"\" -quality 100 "+QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Display/Messages/"+outfilename+".jpg"); if(myProcess.state()!= QProcess::Running) { myProcess.start(program); myProcess.waitForFinished(5000); i=i+1; }
thank you very much for you help!!
-
@filipdns said in loop for not waiting the end of process:
i=i+1;
That means you are skipping one image for every loop iteration.
if(myProcess.state()!= QProcess::Running)
And that means you may skip many more if process is still running. You could have avoided that if you created local QProcess inside the loop...
-
@sierdzio hi, no it's not skipping any image but what do you mean with process inside the loop?
-
@filipdns said in loop for not waiting the end of process:
@sierdzio hi, no it's not skipping any image
OK then you probably have removed
i++
from first line of your loop? Then that has another side effect - until your process exits you are forcing a tight, endless loop. That will eat your CPU, don't do it.Also, if QProcess gets stuck for any reason, that loop will never exit.
but what do you mean with process inside the loop?
for (whatever) { QProcess process; process.start(program); process.waitForStarted(5000); if(process.waitForFinished(5000) == false) qInfo() << "Process had some trouble" << process.errorString() << program; }
-
@sierdzio Yes I removed the I++ from first line. I didn't know that will have effect on my cup, I will change that and see if your advise can do the job, thanks a lot
-
@filipdns said in loop for not waiting the end of process:
@sierdzio Yes I removed the I++ from first line. I didn't know that will have effect on my cup, I will change that and see if your advise can do the job, thanks a lot
You can check the endless loop easily. Print a message at the beginning of the loop:
for (...) { qDebug() << "Loop block begins"; }
If you see lots and lots of these lines (more than the number of images you have) then it's looping tightly as I mentioned in my last reply.
-
@sierdzio I try to move the i=i+1 to the i++ in the line for(int i=0;i<images.count();i++) and it's working fine only if I keep the waitForFinished(5000) otherwise, I have infinit loop
for(int i=0;i<images.count();i++) { //do whatever you need to do QString filename=images[i]; QString outfilename=filename.split(".")[0]; program2=QDir::toNativeSeparators("//DGS1109N007/Echanges_SAA/Affichage/Display/imagmagick/magick ")+ "convert -density 300 -trim "+ QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Messages/"+filename)+"\" -quality 100 "+QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Display/Messages/"+outfilename+".jpg"); if(myProcess2.state()!= QProcess::Running) { myProcess2.start(program2); myProcess2.waitForFinished(5000); //i=i+1; } }
-
-
@jsulm Hello, I seen this advise but I didn't understand how I have to do else than put the process in the loop
-
-
@filipdns oh he is meaning the process declaration may be?
In this case ok, I try
-
@filipdns I try the provided code and it didn't work...
-
@filipdns said in loop for not waiting the end of process:
@jsulm Hello, I seen this advise but I didn't understand how I have to do else than put the process in the loop
Well there's nothing else. Just put it inside. Then you will be certain 100% that next time the loop iterates, it will delete the old process and create a new, fresh one.
-
@sierdzio I just understand what this code it suppose to do and very good idea, I adopt it!! Big thanks !!!!!
for(int i=0;i<images.count();i++) { //do whatever you need to do //qDebug() << "Loop block begins"; filename=images[i]; outfilename=filename.split(".")[0]; program2=QDir::toNativeSeparators("//DGS1109N007/Echanges_SAA/Affichage/Display/imagmagick/magick ")+ "convert -density 300 -trim "+ QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Messages/"+filename)+"\" -quality 100 "+QDir::toNativeSeparators("\"//DGS1109N007/Echanges_SAA/Affichage/Display/Messages/"+outfilename+".jpg"); if(myProcess2.state()!= QProcess::Running) { myProcess2.start(program2); myProcess2.waitForStarted(6000); if(myProcess2.waitForFinished(6000) == false) qInfo() << "Process had some trouble" << myProcess2.errorString() << program; } }
-
@filipdns I don't see you adopting it in your last code snippet...