Unsolved how to communicate qprocess with QTCP socket?
-
In my GUI application, i am running the exe. exe run forever
so i call the exe through Qprocess . Now i want to communicate with the exe.
i gone through the qprocess document. in that, they mention that we have to use qtcp socket.
i can't find any example regarding this? please help me to find through example on Qprocess communicate through QTCP
-
Either you are using the standard in an output channels as described in QProcess documentation or you can do additional information exchange through TCP. TCP exchange you can do as you would set up standard TCP/IPexchange between two applications.
Have a look to the FortuneClient and FortuneServer examples.
-
is there any alternate solution another then the TCP to communicate with the Qprocess.
Because it is very complex to understand and i am new to Qt.You are saying something "standard in an output channels" . Can you mention more about it please.
-
@raghava said in how to communicate qprocess with QTCP socket?:
is there any alternate solution another then the TCP to communicate with the Qprocess.
We don't know, because you have told us nothing about what your sub-process is/does and when, whether it's your own code, whether it is a server which allows multiple clients to connect, or whatever...
-
- I'd say
QLocalSocket
is more appropriate thanQTcpSocket
- You can use
std::cin
/std::cout
to make the two programs dialogue see http://doc.qt.io/qt-5/qprocess.html#communicating-via-channels
- I'd say
-
In my GUI application,My exe is a application that runs forever . untill the user stop it. actually , i can run and communicate with my exe using command in terminal. i want GUI for that.
i have two button start and stop. In start , i am using Qprocess. so the processes run in background.
it's nice upto here. but i want to pass a command to exe and receive the reply from the exe.
start_button{
//exe should run forever
}stop_button{
//stop the execution of exe
}In start_button function , I am using Qprocess to execute the exe. Now i can run my exe background.
how do i communicate with exe? -
@raghava said in how to communicate qprocess with QTCP socket?:
i can run and communicate with my exe using command in terminal
What does that mean? Do you mean: you can type things in with the keyboard while it's running and it reads what you've entered and acts on it (perhaps producing output back)? Or, do you run
yourapp.exe <some argument>
repeatedly? Or what? -
@JonB
my exe runs continously,In terminal,
./myexe<enter>
my application start
after running for 1 minute of running, wait for user command .if i give some command like:
power<enter> , then it display power level
timestamp<enter>, then it display time.are you understanding what i am saying?
-
@raghava
OK, so now you are saying you run an application and it continuously reads fromstdin
, and responds by writing tostdout
.Then should be no need for TCP. Your parent process (which creates the
QProcess
) can write to child'sstdin
viaprocess->write()
to send its "commands", and can read back from child's "response" tostdout
/stderr
via one of theQProcess::read...()
methods (probably inside theQProcess::readyRead...()
slots for signals).BTW, this approach will only work if you launch your sub-process via
QProcess::start()
, not if you want to useQProcess::startDetached()
. -
can you please elaborate you answer.
-
@raghava said in how to communicate qprocess with QTCP socket?:
but i want to pass a command to exe and receive the reply from the exe
Do what @VRonin suggested then: use stdin/stdout. You can see how to do it in QProcess documentation.
-
@jsulm
If he does as @VRonin , as you just suggested, he will have to start using TCP. He has said he does not want to do that, so why can't he use no TCP and stdin/stdout simply just as I suggested?can you please elaborate you answer.
If you mean, can I write code for you, I'm afraid i am not a Qt support person. I'm just a user who tries to give hints here, and I have loads of my own work which I really ought to be doing instead...! :)
-
@JonB said in how to communicate qprocess with QTCP socket?:
If he does as @VRonin , as you just suggested, he will have to start using TCP
How is reading/writing from/to stdin/stdout related to TCP?
It is as simple as http://doc.qt.io/qt-5/qprocess.html#readAllStandardOutput and http://doc.qt.io/qt-5/qiodevice.html#write -
VRonin about 2 hours ago
I'd say QLocalSocket is more appropriate than QTcpSocket
You can use std::cin/std::cout to make the two programs dialogue see http://doc.qt.io/qt-5/qprocess.html#communicating-via-channelsThat's what I meant. I shouldn't have said "TCP", I should have said "Socket". Why does he need to use any socket stuff to emulate interacting with an application which presently works purely via stdin/stdout to the terminal, which is all I'm suggesting he do through
QProcess
? Perhaps there's a misunderstanding. -
@JonB I'm talking about point 2 from @VRonin
"2. You can use std::cin/std::cout to make the two programs dialogue see http://doc.qt.io/qt-5/qprocess.html#communicating-via-channels" -
@jsulm
Ahhh, OK! :)Yes, he can change over to using C++'s std::cin/std::cout if he wants. I just do it directly via
QProcess::read/write
from my Python. They come to the same for the OP: he is attaching stdin/stdouts between parent & child, whichever way you look at it. And no sockets :)