[SOLVED] Execute cmd using qt on Windows.
-
I have a GUI with a button to search a file and button OK to open a file (e.g .txt) using cmd.
In my function_on_buttonBox_OK_ I wrote the follow code:
@
QProcess proc;
QString command = "cmd.exe";
QStringList arguments =
QStringList() << item2;
proc.start(command, arguments);@ps: item2 is a string that contains the directory of my text file that I previously adiquiri.
But has an error: QProcess: Destroyed while process ("cmd.exe") is still running.
Someone help me ?
-
Most probably you are deleting proc before the end of the process. Based on the code snippet that you have published I see that you assign the variable at the stack which means that it will be deleted automatically when it goes out of scope.
-
You can use "waitForStarted":http://qt-project.org/doc/qt-5/qprocess.html#waitForStarted to make sure that cmd.exe is started and then "waitForFinished":http://qt-project.org/doc/qt-5/qprocess.html#waitForFinished to make sure that cmd.exe is finished.
-
Works like this:
@ QString paths = item2;
QProcess proc;
QString command = "cmd.exe";
QStringList arguments =
QStringList() << "/c" << paths ;proc.start(command, arguments); if(proc.waitForStarted()){ qDebug() << "Starting"; } proc.waitForFinished(-1); qDebug() << "finish";@
But I have a question:
Why does my GUI freezes when I open a file in directory C: (system) and does not freezes when I open in directory E: (I divided my HD into two parts) ?