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
QtWS25 Last Chance

get error message from qprocess

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 4.7k Views
  • 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 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
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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
          0
          • SGaistS SGaist

            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 last edited by
            #5

            @SGaist
            what about errorString()?

            jsulmJ 1 Reply Last reply
            0
            • U user4592357

              @SGaist
              what about errorString()?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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
              1
              • jsulmJ jsulm

                @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 last edited by
                #7

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

                jsulmJ 1 Reply Last reply
                0
                • U user4592357

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

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 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
                  0
                  • jsulmJ jsulm

                    @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 last edited by user4592357
                    #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.

                    jsulmJ 1 Reply Last reply
                    0
                    • U user4592357

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

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #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
                      0
                      • jsulmJ jsulm

                        @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 last edited by
                        #11

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

                        jsulmJ 1 Reply Last reply
                        0
                        • U user4592357

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

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 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
                          0
                          • jsulmJ jsulm

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

                            U Offline
                            U Offline
                            user4592357
                            wrote on last edited by
                            #13

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

                            jsulmJ 1 Reply Last reply
                            0
                            • U user4592357

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

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by jsulm
                              #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

                              • Login

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