executing the OS command using QProcess
-
hi
Debian OS
Qt Creator 10.0.2 Based on Qt 6.4.2 (GCC 13.2.0, x86_64)ask for help, how to fix it
This code works perfectly. Converts a file to pdf:QProcess *process = new QProcess(parent); QStringList list; process->waitForStarted(); process->waitForReadyRead(); process->start("unoconv", list <<"-f"<<"pdf"<<"-o"<<"/somepath/file.pdf"<<"/somepath/somefile.odt"); process->waitForFinished();
This code does not work. The file is not being copied:
QProcess *process = new QProcess(parent); QStringList list; process->waitForStarted(); process->waitForReadyRead(); process->start("/usr/bin/dd", list <<"if='/somepath/somepath/file.pdf'" << "of='/somepath/file.pdf'"); process->waitForFinished();
At first I tried to copy using 'cp'. It doesn't work either
Moreover, both commands work perfectly in the OS console -
-
What's wrong with QFile::copy() when you only want to copy a file to another location?
-
@gaargot
Apart from @Christian-Ehrlicher's suggestion that if you want to copy a file do it viaQFile::copy()
rather than an OS command. Although your code "works" you should at least be aware that it is "wrong". You are callingwaitForStarted()
andwaitForReadyRead()
before you havestart()
ed the process. That makes no sense, they probably just return immediately since there is nothing running to wait for! If you needed them here --- which you do not --- they should come afterstart()
and beforewaitForFinished()
, for future reference.