Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QProcess - strange behavior
Adrian.Aioanei last edited by
I have meet a strange problem with QProcess. I have an executable how write some data into a file. If i run the executable from widows explorer it works and write data to the file but if i use QProcess, the executable starts but at the end do not write data to the file.
I have read on the internet about this thing and some people say it could be block from the antivirus but i turn of and still the same results.
When i start the process i use something like this
proc.start("Exe path", QIODevice::ReadWrite);
Have anyone some idea about this think?
DonMirkoni last edited by
You can try like this
QString path = QCoreApplication::applicationDirPath (); path.append("/nameapp.exe"); QString path1="file:///"; QString path2 = path1+path; QDesktopServices::openUrl(QUrl(path2, QUrl::TolerantMode));
You should add handling for the standard output and standard error channels of your QProcess to see what is going on.
Adrian.Aioanei last edited by Adrian.Aioanei
This works in some way but my application crash because doesn't find any data in the file to print to the interface. I have a function for a pushed button and looks like this:
QString path = QCoreApplication::applicationDirPath (); path.append("/testExecutabele.exe"); QString path1="file:///"; QString path2 = path1+path; QDesktopServices::openUrl(QUrl(path2, QUrl::TolerantMode)); this->proc.start(path2, QIODevice::ReadWrite); this->proc.waitForFinished(-1); AddData data; //class data.insertDataToLabels(); //function how read data from the file created by testExecutabele.exe
In textExecutabele.exe i have put a delay of 5000 ms. In a normal way when i push the button i will need to wait 5 sec before to crash if doesn't find data in file but in this case if in the file is empty it crash in the moment when i push the button. So is possible to be a probleme at this->proc.waitForFinished(-1); ? If i delete last tow line from the function (method from insert data to labels) everything works fine, the executable run and the file is created.
The entire application run on the same thread, so all the code will be executed sequentially, write?
Your process won't start, it's not a valid path to start an application with QProcess.
You should check the result from exitCode.
And you should also check the code from AppData, an empty file should not be able to crash your application, that's a pretty bad flaw.