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. ....forwarded to the calling process.??

....forwarded to the calling process.??

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 6 Posters 1.6k Views 2 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.
  • A Anonymous_Banned275

    @JonB RTFM??

    nt QProcess::execute(const QString &program, const QStringList &arguments)
    Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.

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

    @AnneRanch said in ....forwarded to the calling process.??:

    @JonB RTFM??

    I beg your pardon?

    I explained it is a static function. I explained it means that writing QP->execute() does not open QP, and that is why your output shows

    QIODevice::read (QProcess): device not open
    

    error.

    For your purpose here it is much simpler to use QProcess::start(). QProcess::execute() offers you no advantage over that, only makes life harder. Up to you. Earlier on @ChrisW67 showed code if you really want to use execute() [though I have to say, I did not find it worked correctly at least in Qt 5.15, Ubuntu], his later post shows using start(). Also with execute() you will never have the option of being able to connect signals.

    A 1 Reply Last reply
    1
    • JonBJ JonB

      @AnneRanch said in ....forwarded to the calling process.??:

      @JonB RTFM??

      I beg your pardon?

      I explained it is a static function. I explained it means that writing QP->execute() does not open QP, and that is why your output shows

      QIODevice::read (QProcess): device not open
      

      error.

      For your purpose here it is much simpler to use QProcess::start(). QProcess::execute() offers you no advantage over that, only makes life harder. Up to you. Earlier on @ChrisW67 showed code if you really want to use execute() [though I have to say, I did not find it worked correctly at least in Qt 5.15, Ubuntu], his later post shows using start(). Also with execute() you will never have the option of being able to connect signals.

      A Offline
      A Offline
      Anonymous_Banned275
      wrote on last edited by
      #10

      @JonB before somebody posts another example how to modify a+b to b+a
      kindly please provide reference to correct this official QT document when STATIC is implemented .

      RTFM and note that "execute" is referenced under "static".

      nt QProcess::execute(const QString &program, const QStringList &arguments)
      Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.

      To the contributors whose code "waits for finish " - please note the above highlighted part.

      I appreciate all constructive contributions, however, somehow the original post OBJECTIVE to discuss how data is forwarded to calling process is being masked by usual personal innuendos ( format your code ,,, we told you so ... etc) .
      PLEASE stop that.

      Christian EhrlicherC JonBJ 2 Replies Last reply
      0
      • A Anonymous_Banned275

        @JonB before somebody posts another example how to modify a+b to b+a
        kindly please provide reference to correct this official QT document when STATIC is implemented .

        RTFM and note that "execute" is referenced under "static".

        nt QProcess::execute(const QString &program, const QStringList &arguments)
        Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.

        To the contributors whose code "waits for finish " - please note the above highlighted part.

        I appreciate all constructive contributions, however, somehow the original post OBJECTIVE to discuss how data is forwarded to calling process is being masked by usual personal innuendos ( format your code ,,, we told you so ... etc) .
        PLEASE stop that.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #11

        @AnneRanch said in ....forwarded to the calling process.??:

        how data is forwarded to calling process

        What exactly do you want to know here? How it's done internally so you can read it with the functions fomr QProcess? If not - what else?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • A Anonymous_Banned275

          @JonB before somebody posts another example how to modify a+b to b+a
          kindly please provide reference to correct this official QT document when STATIC is implemented .

          RTFM and note that "execute" is referenced under "static".

          nt QProcess::execute(const QString &program, const QStringList &arguments)
          Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.

          To the contributors whose code "waits for finish " - please note the above highlighted part.

          I appreciate all constructive contributions, however, somehow the original post OBJECTIVE to discuss how data is forwarded to calling process is being masked by usual personal innuendos ( format your code ,,, we told you so ... etc) .
          PLEASE stop that.

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

          @AnneRanch said in ....forwarded to the calling process.??:

          kindly please provide reference to correct this official QT document when STATIC is implemented .

          Kindly note that I did precisely that in the post you are asking about

          int QProcess::execute(const QString &program, const QStringList &arguments = {}) is static

          That's what I wrote. It has the link to the documentation. Is that what you wanted that you're not happy with? Or something else?

          RTFM and note that "execute" is referenced under "static".

          I do "RTFM", thank you very much.

          • If you use QProcess::execute() you will find it difficult to get any output correctly/reliably. IMHO.
          • If you use QProcess::start() plus some kind of QProcess::waitForFinished() you will be able to use QProcess::read...() to read the output from the spawned process.

          Why not just try saying "thank you"? That would be really nice. Or something without the "F" in it when people try to help you?

          A 1 Reply Last reply
          1
          • JonBJ JonB

            @AnneRanch said in ....forwarded to the calling process.??:

            kindly please provide reference to correct this official QT document when STATIC is implemented .

            Kindly note that I did precisely that in the post you are asking about

            int QProcess::execute(const QString &program, const QStringList &arguments = {}) is static

            That's what I wrote. It has the link to the documentation. Is that what you wanted that you're not happy with? Or something else?

            RTFM and note that "execute" is referenced under "static".

            I do "RTFM", thank you very much.

            • If you use QProcess::execute() you will find it difficult to get any output correctly/reliably. IMHO.
            • If you use QProcess::start() plus some kind of QProcess::waitForFinished() you will be able to use QProcess::read...() to read the output from the spawned process.

            Why not just try saying "thank you"? That would be really nice. Or something without the "F" in it when people try to help you?

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #13

            @JonB

            I LIKE TO KNOW WHY THIS DOES NOT WORK WHEN USED A STATIC.....

            'WHERE DOES IT SAY THAT IN THIS SNIPPET OF OFFICIAL DOCUMENTATION
            ?????
            ?
            /
            PLEASE
            no more personal remarks / opinions why it should not be used as STATIC .....
            '
            PLEASE
            pay attention to highlighted part which was the original subject if my post and is continually derailed by opinions....

            int QProcess::execute(const QString &program, const QStringList &arguments = {})

            Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.

            The environment and working directory are inherited from the calling process.

            Argument handling is identical to the respective start() overload.

            If the process cannot be started, -2 is returned. If the process crashes, -1 is returned. Otherwise, the process' exit code is returned.

            See also start().

            JonBJ 1 Reply Last reply
            0
            • A Anonymous_Banned275

              @JonB

              I LIKE TO KNOW WHY THIS DOES NOT WORK WHEN USED A STATIC.....

              'WHERE DOES IT SAY THAT IN THIS SNIPPET OF OFFICIAL DOCUMENTATION
              ?????
              ?
              /
              PLEASE
              no more personal remarks / opinions why it should not be used as STATIC .....
              '
              PLEASE
              pay attention to highlighted part which was the original subject if my post and is continually derailed by opinions....

              int QProcess::execute(const QString &program, const QStringList &arguments = {})

              Starts the program program with the arguments arguments in a new process, waits for it to finish, and then returns the exit code of the process. Any data the new process writes to the console is forwarded to the calling process.

              The environment and working directory are inherited from the calling process.

              Argument handling is identical to the respective start() overload.

              If the process cannot be started, -2 is returned. If the process crashes, -1 is returned. Otherwise, the process' exit code is returned.

              See also start().

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

              @AnneRanch said in ....forwarded to the calling process.??:

              no more personal remarks / opinions why it should not be used as STATIC .....

              When you write:

              QProcess *QP = new QProcess();
              QP->execute(command);
              qDebug() << QP->readAllStandardOutput();
              

              it won't work because QProcess::execute() is a static method. You will get nothing back, and an error message from the last line saying the QProcess is not open. A static method does not operate on any instance you happen to call it on. The code above is really:

              QProcess *QP = new QProcess();
              QProcess::execute(command);
              qDebug() << QP->readAllStandardOutput();
              

              You can see the QP instance has not been used to open or execute the command. You cannot read from it. QProcess::execute() has its own internal QProcess instance it creates and destroys, you cannot access it.

              That is how static class methods work in C++.

              1 Reply Last reply
              2
              • Chris KawaC Online
                Chris KawaC Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by Chris Kawa
                #15

                As mentioned above using a static method means you don't get an instance of the class that you can use non-static methods on. That means if you run QProcess::execute it internally creates a QProcess instance that you don't get access to. This means you can't use QProcess::readAllStandardOutput because that is not a static method and you don't have access to an instance you can call it on. If you create another instance they don't share the output.

                Calling static method on a non-static object (so QP->execute) is just something that C++ lets you do, but it's just syntax sugar over static call and it has nothing to do with the QP instance. Those are not QProcess or Qt topics. That's just how static functions work in C++.

                All that doesn't mean documentation is wrong. With the static QProcess::execute a stream forwarding is used, meaning that if the subprocess writes to the output, e.g. with std::cout << "hello" the calling process catches it and puts it into its own output stream, so you will see it in the output stream of the calling process. If you want to catch it to, for example, put it in a textbox or something, you can do it but it's quite complicated.
                First you need to do standard cout and cerr stream redirection. I'm not gonna go into detail because there's enough materials out there and it's not Qt specific topic.
                Second, because QProcess::execute is a blocking call you probably will have to start another thread to read that output in realtime, or better yet start that QProcess::execute in another thread so it doesn't block your UI.
                Third, even if you redirect cout to some sort of handler of yours that subprocess output will be mixed with that of the calling process and you'll have to do some parsing to differentiate which part of the output is from which process.

                So that being said static QProcess::execute is not a good choice for the task of reading the output of the called process. It can be done if someone is stubborn enough, but it requires a lot of pointless work that can be replaced with just a few lines of creating a QProcess instance, calling start, waitForFinished and readAllStandardOutput.

                QProcess::execute is a convenience shortcut for cases when you don't need to interact with the process you're calling.

                The documentation is ok, just doesn't go into details where the streams are redirected, because it's not really meant to be used this way. If you want then you have to do some digging on stream redirection yourself, but that's really self inflicted pain that is not necessary.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  ChrisW67
                  wrote on last edited by ChrisW67
                  #16

                  Life is too short. Once again we have the "I'll delete all my posts" response.

                  hskoglundH JonBJ 2 Replies Last reply
                  1
                  • C ChrisW67

                    Life is too short. Once again we have the "I'll delete all my posts" response.

                    hskoglundH Offline
                    hskoglundH Offline
                    hskoglund
                    wrote on last edited by
                    #17

                    @ChrisW67 Long time ago I posted a reply on a similar toplc and got a toxic answer.
                    Once bitten twice shy...

                    1 Reply Last reply
                    1
                    • C ChrisW67

                      Life is too short. Once again we have the "I'll delete all my posts" response.

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

                      @ChrisW67

                      Life is too short. Once again we have the "I'll delete all my posts" response.

                      Wow, who would be so rude/ungrateful after everybody has posted so much in response trying to help as to delete all their posts?!

                      @hskoglund

                      Long time ago I posted a reply on a similar toplc and got a toxic answer.
                      Once bitten twice shy...

                      You are right! I keep forgetting this, thinking it will be better and would be nice to help someone. I need to take the "bitten" ["mauled"? ;-) ] lesson to heart!

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #19

                        I've restored them so we can refer to them when the same question is asked in two weeks again.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        1

                        • Login

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