get error message from qprocess
-
QProcess
haserror()
method which returns an enum, and anexitCode()
method which returns an int.
how can i get the actual message why e.g.startDetached()
failed? maybe passexitCode()
tostrerror()
? -
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 -
i don't want to write to std out/err, i want to print the error message in application, on some widget
-
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.
-
@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. -
-
@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. -
@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.
-
@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. -
@user4592357 "maybe pass exitCode() to strerror()" - what do you mean by that? Do you mean stderror?
-
-
@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.