Qprocess runs correctly in debug but in release mode it doesn't run correctly
-
Hi and welcome to devnet,
First thing to do: add error checks to your code.
You are doing the assumption that everything goes well all the time which is wrong.Next, split the arguments properly. Each space in your string means that it should be a separated element in the argument list as explained in QProcess's documentation.
-
-
@TahmDev
Hi
Hook up to the signal
https://doc.qt.io/qt-5/qprocess.html#errorOccurred
and see if it list something when it don't work. -
Please take the time to read the class documentation:
QProcess::errorOccurred
QProcess::error
etc.As for your code, it will run faster in release than debug mode. The way you wrote your second QProcess code is wrong. You assume that it has ended after the call to closeWriteChannel which is an error.
You should learn how to use it in asynchronous mode.
By the way, you are "leaking" QProcess objects there. They will only be destroyed when the parent is which means you can still fill memory with them each time you call on_button_clicked.
-
@TahmDev said in Qprocess runs correctly in debug but in release mode it doesn't run correctly:
QProcess *inputList= new QProcess(this);
inputList-> start();
I seem to be the only person commenting on this, but what does this do? You are using overload https://doc.qt.io/qt-5/qprocess.html#start-2, which says
Starts the program set by
setProgram()
...and https://doc.qt.io/qt-5/qprocess.html#setProgram says:
Set the program to use when starting the process. This function must be called before
start()
.Show me how you (apparently) reckon
inputList->write("xinput list");
runsxinput list
? So I don't understand how you are running any program at all for this? Whether this is connected to debug/release I cannot say....[EDIT See my topic https://forum.qt.io/topic/118969/qprocess-with-no-program-to-run for this issue which conused me and may confuse any reader of the code!]
-
@SGaist I read the documents, I'm not a pro, but I wrote many connect signal slots for error occured and state changed to my processes ... Everything works fine but the problem is that the second processes starts soon...if you can help me I would be grateful
-
Guys thanks for all your advices ...I figured out the problem, the linux command related to inputattach makes inputattach to run in background and returns to qt so fast that the attachment has not happened yet.
I added a timer to my program and after 1000ms the other process will be initiated.
Everything is fine then -
@TahmDev said in Qprocess runs correctly in debug but in release mode it doesn't run correctly:
I added a timer to my program and after 1000ms the other process will be initiated.
Everything is fine thenYou know that this is going to haunt you ?
Did you check my suggestion of using QProcess asynchronous nature to manage the commands you are running ?