Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to communicate qprocess with QTCP socket?
Forum Updated to NodeBB v4.3 + New Features

how to communicate qprocess with QTCP socket?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 5 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R raghava

    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.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #4

    @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...

    1 Reply Last reply
    2
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #5
      1. I'd say QLocalSocket is more appropriate than QTcpSocket
      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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • R Offline
        R Offline
        raghava
        wrote on last edited by
        #6

        @JonB

        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?

        JonBJ jsulmJ 2 Replies Last reply
        0
        • R raghava

          @JonB

          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?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #7

          @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?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            raghava
            wrote on last edited by
            #8

            @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?

            JonBJ 1 Reply Last reply
            0
            • R raghava

              @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?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #9

              @raghava
              OK, so now you are saying you run an application and it continuously reads from stdin, and responds by writing to stdout.

              Then should be no need for TCP. Your parent process (which creates the QProcess) can write to child's stdin via process->write() to send its "commands", and can read back from child's "response" to stdout/stderr via one of the QProcess::read...() methods (probably inside the QProcess::readyRead...() slots for signals).

              BTW, this approach will only work if you launch your sub-process via QProcess::start(), not if you want to use QProcess::startDetached().

              1 Reply Last reply
              2
              • R Offline
                R Offline
                raghava
                wrote on last edited by
                #10

                can you please elaborate you answer.

                1 Reply Last reply
                0
                • R raghava

                  @JonB

                  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?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  @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.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  JonBJ 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @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.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #12

                    @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?

                    @raghava

                    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...! :)

                    jsulmJ 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @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?

                      @raghava

                      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...! :)

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @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

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      JonBJ 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @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

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #14

                        @jsulm
                        @VRonin posted:

                        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-channels

                        That'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.

                        jsulmJ 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @jsulm
                          @VRonin posted:

                          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-channels

                          That'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.

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          @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"

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          JonBJ 1 Reply Last reply
                          2
                          • jsulmJ jsulm

                            @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"

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #16

                            @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 :)

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved