Solved QProcess with no program to run
-
Over in https://forum.qt.io/topic/118956/qprocess-runs-correctly-in-debug-but-in-release-mode-it-doesn-t-run-correctly the OP's code reads:
QProcess *inputList= new QProcess(this); inputList-> start(); inputList->write("xinput list"); inputList->write("\n"); inputList->closeWriteChannel(); ui-> text Edit->insertPlainTextEdit( inputList-> readAllStandardOutPut());
to which I replied in https://forum.qt.io/topic/118956/qprocess-runs-correctly-in-debug-but-in-release-mode-it-doesn-t-run-correctly/7 essentially saying:
QProcess *inputList= new QProcess(this);
inputList-> start();
I seem to be the only person commenting on this, but what does this do?
Since nobody commented and the OP seems happy, could someone explain what this does/how this works and, most importantly, where this is documented against
QProcess
, please? -
@JonB hey jonB, sorry for my late reply.
Problem with the code I sent was that I typed it through my cellphone, therefore I missed a line before start to setProgram("/bin/bash")
And for the xinput list...in linux terminal it returns the list of all the input devices connected to the system. -
I didn't comment in that post but I was thinking "this will simply cause a FailedToStart error".
-
@JonB I assume the relevant documentation part is this one:
https://doc.qt.io/qt-5/qprocess.html#details
hidden, but it's there 🤷♂️
-
@J-Hilk
No, I do not understand! I have read that, and am well aware that you can use read/write to communicate with a running process. I believe that is all that section is saying(?). That is not the case here! There is no process specified to run as argument toQProcess::start()
here. So what process is this writing to?? It appears that something is going to do something like: read whatever arrives, terminated by a\n
, and then do something in the way of "executing" what was sent (xinput list\n
in this case). I take it that is what the OP is claiming happens??Where in the world is anything like this explained anywhere, if that is the case??
-
@JonB said in QProcess with no program to run:
the post in the other thread, the OP does no error checking, if you did, he would get a failed to start error due to the missing program.
That said, why should a call to the underlying QIODevice crash or otherwise behave out of order ?
It should return -1 as, the writing will fail, but thats about it. -
@J-Hilk
OK, so now you seem to be agreeing with my comment that you cannot goprocess->start(this)
m like he does? It is not going to execute thexinput list\n
he shows? Yet he seems happy with that and claims all is working?? That is what I am trying to understand here?I see only two overloads:
void QProcess::start(const QString &program, const QStringList &arguments, QIODevice::OpenMode mode = ReadWrite) void QProcess::start(QIODevice::OpenMode mode = ReadWrite)
So his
inputList-> start()
can only match the second one. How does that OP's comment "But when I run the inputattach in my qt in debug mode, it works properly and when I run "xinput list" it shows me the added device but in relaese mode it doesn't work " work? I don't see this will ever "run"xinput list
, which is why I commented as I did, that is what I'm trying to understand? I thought I knew all there is to know aboutQProcess
, this has thrown me :) If he had written "I got rid of that part of the code" then I would have no problem....! -
@JonB hey jonB, sorry for my late reply.
Problem with the code I sent was that I typed it through my cellphone, therefore I missed a line before start to setProgram("/bin/bash")
And for the xinput list...in linux terminal it returns the list of all the input devices connected to the system. -
@JonB the OP did not copy and past, because this line shouldn't compile
ui-> text Edit->insertPlainTextEdit( inputList-> readAllStandardOutPut());
So I assume there's stuff missing.
-
@TahmDev said in QProcess with no program to run:
And for the xinput list...in linux terminal it returns the list of all the input devices connected to the system.
Yes, I realize this :)
Problem with the code I sent was that I typed it through my cellphone, therefore I missed a line before start to setProgram("/bin/bash")
Ah ha! OK, now at least make some sense to me :) For that you would have been better/simpler to use the
-c
argument for one command:process->start("/bin/bash", QStringList() << "-c" << "xinput list"); // or in this case just process->start("xinput", QStringList() << "list");
but at least I understand what is going on now! :)
-
@JonB yeah actually I knew it... But it was sooo frustrating for me...K was trying so hard to make my app work and it wasn't therefore I tried soo many different paths and commands😁