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. get error message from qprocess
Forum Updated to NodeBB v4.3 + New Features

get error message from qprocess

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 4.8k 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.
  • U Offline
    U Offline
    user4592357
    wrote on 5 Feb 2019, 19:14 last edited by
    #1

    QProcess has error() method which returns an enum, and an exitCode() method which returns an int.
    how can i get the actual message why e.g. startDetached() failed? maybe pass exitCode() to strerror()?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 5 Feb 2019, 19:48 last edited by
      #2

      Don't use startDetached() when you want to get the stdout/stderr messages. See http://doc.qt.io/qt-5/qprocess.html#startDetached
      When a process is started with start() you can read stdout/stderr: http://doc.qt.io/qt-5/qprocess.html#readAllStandardError

      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
      2
      • U Offline
        U Offline
        user4592357
        wrote on 5 Feb 2019, 20:24 last edited by
        #3

        i don't want to write to std out/err, i want to print the error message in application, on some widget

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Feb 2019, 20:29 last edited by
          #4

          Hi,

          What @Christian-Ehrlicher suggested is for your to be able to read the output generated by the application started using QProcess. What you do with said output is up to you.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          U 1 Reply Last reply 6 Feb 2019, 04:50
          0
          • S SGaist
            5 Feb 2019, 20:29

            Hi,

            What @Christian-Ehrlicher suggested is for your to be able to read the output generated by the application started using QProcess. What you do with said output is up to you.

            U Offline
            U Offline
            user4592357
            wrote on 6 Feb 2019, 04:50 last edited by
            #5

            @SGaist
            what about errorString()?

            J 1 Reply Last reply 6 Feb 2019, 05:23
            0
            • U user4592357
              6 Feb 2019, 04:50

              @SGaist
              what about errorString()?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 6 Feb 2019, 05:23 last edited by
              #6

              @user4592357 said in get error message from qprocess:

              what about errorString()?

              There is no such thing. You can either connect a slot to http://doc.qt.io/qt-5/qlistwidget.html#selectedItems or call http://doc.qt.io/qt-5/qprocess.html#error. You will get an enum value (one of the http://doc.qt.io/qt-5/qprocess.html#ProcessError-enum), then you can do what ever you want with it. Like:

              ProcessError error = process.error();
              switch(error) {
              case FailedToStart:
                  ui->label->setText("Failed to start");
              ...
              }
              

              To get exit code call http://doc.qt.io/qt-5/qprocess.html#exitCode
              It's all in the documentation.

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

              U 1 Reply Last reply 6 Feb 2019, 05:45
              1
              • J jsulm
                6 Feb 2019, 05:23

                @user4592357 said in get error message from qprocess:

                what about errorString()?

                There is no such thing. You can either connect a slot to http://doc.qt.io/qt-5/qlistwidget.html#selectedItems or call http://doc.qt.io/qt-5/qprocess.html#error. You will get an enum value (one of the http://doc.qt.io/qt-5/qprocess.html#ProcessError-enum), then you can do what ever you want with it. Like:

                ProcessError error = process.error();
                switch(error) {
                case FailedToStart:
                    ui->label->setText("Failed to start");
                ...
                }
                

                To get exit code call http://doc.qt.io/qt-5/qprocess.html#exitCode
                It's all in the documentation.

                U Offline
                U Offline
                user4592357
                wrote on 6 Feb 2019, 05:45 last edited by
                #7

                @jsulm
                https://doc.qt.io/qt-5/qiodevice.html#errorString

                J 1 Reply Last reply 6 Feb 2019, 05:50
                0
                • U user4592357
                  6 Feb 2019, 05:45

                  @jsulm
                  https://doc.qt.io/qt-5/qiodevice.html#errorString

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 6 Feb 2019, 05:50 last edited by
                  #8

                  @user4592357 Oh, yes, forgot about inherited methods, you're right :-)
                  But keep in mind that this will not necessarily return errors specific to QProcess (like QProcess::Crashed) as QIODevice does not know anything about them. You still should use error() from QProcess also.

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

                  U 1 Reply Last reply 6 Feb 2019, 05:53
                  0
                  • J jsulm
                    6 Feb 2019, 05:50

                    @user4592357 Oh, yes, forgot about inherited methods, you're right :-)
                    But keep in mind that this will not necessarily return errors specific to QProcess (like QProcess::Crashed) as QIODevice does not know anything about them. You still should use error() from QProcess also.

                    U Offline
                    U Offline
                    user4592357
                    wrote on 6 Feb 2019, 05:53 last edited by user4592357 2 Jun 2019, 05:57
                    #9

                    @jsulm
                    should i do like this?

                    if (!process.start(path, args))
                    {
                        auto err = process.error();
                        switch (err)
                        ...
                    }
                    

                    or catch errorOccurred() signal?

                    i don't need specific handling for each type of error, i just need one string indicating the error.

                    J 1 Reply Last reply 6 Feb 2019, 05:58
                    0
                    • U user4592357
                      6 Feb 2019, 05:53

                      @jsulm
                      should i do like this?

                      if (!process.start(path, args))
                      {
                          auto err = process.error();
                          switch (err)
                          ...
                      }
                      

                      or catch errorOccurred() signal?

                      i don't need specific handling for each type of error, i just need one string indicating the error.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 6 Feb 2019, 05:58 last edited by jsulm 2 Jun 2019, 05:58
                      #10

                      @user4592357 I would catch the signal as an error can occur after the process was successfully started.
                      If you only want to know whether the process was started then the first approach is easier.

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

                      U 1 Reply Last reply 6 Feb 2019, 05:59
                      0
                      • J jsulm
                        6 Feb 2019, 05:58

                        @user4592357 I would catch the signal as an error can occur after the process was successfully started.
                        If you only want to know whether the process was started then the first approach is easier.

                        U Offline
                        U Offline
                        user4592357
                        wrote on 6 Feb 2019, 05:59 last edited by
                        #11

                        @jsulm
                        okay and i initially asked this: maybe pass exitCode() to strerror()? what about that?

                        J 1 Reply Last reply 6 Feb 2019, 06:01
                        0
                        • U user4592357
                          6 Feb 2019, 05:59

                          @jsulm
                          okay and i initially asked this: maybe pass exitCode() to strerror()? what about that?

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 6 Feb 2019, 06:01 last edited by
                          #12

                          @user4592357 "maybe pass exitCode() to strerror()" - what do you mean by that? Do you mean stderror?

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

                          U 1 Reply Last reply 6 Feb 2019, 06:03
                          0
                          • J jsulm
                            6 Feb 2019, 06:01

                            @user4592357 "maybe pass exitCode() to strerror()" - what do you mean by that? Do you mean stderror?

                            U Offline
                            U Offline
                            user4592357
                            wrote on 6 Feb 2019, 06:03 last edited by
                            #13

                            @jsulm
                            no. http://man7.org/linux/man-pages/man3/strerror.3.html

                            J 1 Reply Last reply 6 Feb 2019, 06:10
                            0
                            • U user4592357
                              6 Feb 2019, 06:03

                              @jsulm
                              no. http://man7.org/linux/man-pages/man3/strerror.3.html

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 6 Feb 2019, 06:10 last edited by jsulm 2 Jun 2019, 06:19
                              #14

                              @user4592357 strerror is not about exit code but errors occurring during run time of the application. There is no standard for exit codes. The only thing which is usually a valid assumption is: 0 means "everything fine". Everything != 0 signals an issue. But what exactly an exit code means is up to the application.

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

                              1 Reply Last reply
                              1

                              3/14

                              5 Feb 2019, 20:24

                              topic:navigator.unread, 11
                              • Login

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