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 5.2k 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.
  • 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