QProcess "start" s, but "exexute "cannot start process ?
-
Here is a snippet giving contradictory results.
Passes waitForStarted - no wait
Return -2 " If the process cannot be started, -2 is returned"
Should this read "if execution " cannot be... " ?"start" process did not wait , but now it cannot be started ???
Can somebody help me lead me to solution?
I am little lost here,
QString program = "../../../Examples/Qt-5.15.2/bluetooth/btscanner"; QStringList arguments; arguments << "null" << "null"; I am not sure if these values are correct . btscanner does not expect arguments, but QProcess does QProcess *myProcess = new QProcess(this); myProcess->start(program, arguments); myProcess->waitForStarted(); passes here , no noticeable wait at all qDebug()<<("TASK waitForStarted breakpoint Function ")<<__FUNCTION__<< ("@line ")<<__LINE__; //" If the process cannot be started, -2 is returned" direct doc quote **bolded text** int result = myProcess->execute(program, arguments); result = -2 HERE qDebug()<<("TASK execute break point Function ")<<__FUNCTION__<< ("@line ")<<__LINE__;
-
@AnneRanch said in QProcess "start" s, but "exexute "cannot start process ?:
..../Examples/Qt-5.15.2/bluetooth/btscanner
Is that
btscanner
just the top-level directory of the example project, wherebtscanner.pro
lives? You have to pass the path to the actual built executable within it whatever that might be. Maybe something more like (I don't know, you will have to look around your hierarchy)..../Examples/Qt-5.15.2/bluetooth/btscanner/build-Debug/btscanner
? -
@AnneRanch
If you have no arguments to pass to yourbtscanner
, remove thearguments << "null" << "null";
. Just pass the empty arguments list created by theQStringList arguments;
statement.You would never want to call both
QProcess::start()
andQProcess::execute()
. These will (attempt to) run your process twice. You would use only one or the other.QProcess::start()
never blocks/waits. It only starts the process of running another a program. If the subprocess cannot be started,QProcess::waitForStarted()
will return immediately. It will returnfalse
in this case. Check the return result frommyProcess->waitForStarted()
.QProcess::execute()
returns-2
if the subprocess cannot be started.My guess would be that the (relative) path you specify is incorrect to reach wherever the
btscanner
executable is located. Try:qDebug() << QFileInfo("../../../Examples/Qt-5.15.2/bluetooth/btscanner").exists();
-
@JonB said in QProcess "start" s, but "exexute "cannot start process ?:
@AnneRanch
If you have no arguments to pass to yourbtscanner
, remove thearguments << "null" << "null";
. Just pass the empty arguments list created by theQStringList arguments;
statement.You would never want to call both
QProcess::start()
andQProcess::execute()
. These will (attempt to) run your process twice. You would use only one or the other.QProcess::start()
never blocks/waits. It only starts the process of running another a program. If the subprocess cannot be started,QProcess::waitForStarted()
will return immediately. It will returnfalse
in this case. Check the return result frommyProcess->waitForStarted()
.QProcess::execute()
returns-2
if the subprocess cannot be started.My guess would be that the (relative) path you specify is incorrect to reach wherever the
btscanner
executable is located. Try:qDebug() << QFileInfo("../../../Examples/Qt-5.15.2/bluetooth/btscanner").exists();
U
PDATE
Thanks for very constructive and useful post.
I cannot believe I can make so many errors in few lines of code.I am including the latest code , please be aware that it is still a test / under construction , code - my primary goal to "execute btscanner" and towards that goal usually have more comments / debug than code.
My first error was that I did not follow my own rules and did not verify the access / path to "btscanner" file.
I wonder if there is a canned Qt program to :FIND THE FILE - similar to "find" command.
So far I have not used "system" calls in Qt.I am little puzzled with "start" and "execute".
start does not return value and "wait for started" does not "wait" if process did not start.
So what "state" is "wait" monitoring if it is not "started" ?"execute" on the other hand also starts process.
It looks as "start" is an intermediate step and using "execute" makes more sense.
Either way - my "execute" still returns -2
Working on that problemqDebug()<<("Function ")<<__FUNCTION__<< ("@line ")<<__LINE__; // QObject *parent = nullptr; ///home/qt/Qt/Examples/Qt-5.15.2/bluetooth/btscanner /// initialize QProcess *myProcess = new QProcess(); QString program = "../../../../../Examples/Qt-5.15.2/bluetooth/btscanner"; QStringList arguments; // leave unassigned (?) arguments << "null" << "null"; // verify program file qDebug() << QFileInfo("../../../../../Examples/Qt-5.15.2/bluetooth/btscanner").exists(); TOK qDebug() << QFileInfo(program).exists(); TOK qDebug() << QFileInfo("home/qt/Qt/Examples/Qt-5.15.2/bluetooth/btscanner").exists(); FAILEd - expected // test start "process" - actually progrem myProcess->start(); // no argument passed TOK // test wait for start int wait_result = myProcess->waitForStarted(); TOK // execute (?) PROGRAM //If the process cannot be started, -2 is returned int result_execute = myProcess->execute(program); // no arguments FAILED qDebug()<<("TASK *parent (?) Function ")<<__FUNCTION__<< ("@line ")<<__LINE__;
-
@AnneRanch said in QProcess "start" s, but "exexute "cannot start process ?:
..../Examples/Qt-5.15.2/bluetooth/btscanner
Is that
btscanner
just the top-level directory of the example project, wherebtscanner.pro
lives? You have to pass the path to the actual built executable within it whatever that might be. Maybe something more like (I don't know, you will have to look around your hierarchy)..../Examples/Qt-5.15.2/bluetooth/btscanner/build-Debug/btscanner
? -
@AnneRanch If you want to use the start call of QProcess without arguement then ,
program to be started set by setProgram() with arguments set by setArguments()as @JonB suggested you need to mention the program string which directly points to the executable btscanner
-
SOLVED
I had errors in executable project link - both path and the executable.
Appreciate the help.