Unsolved QProcess arguments are not passed using class method.
-
Hello,
I encountered an issue and I'm not sure if it's a bug or I am calling the method wrong.
I am trying to call Qt installer framework's updater to check for updates and if there are then I would notify the user.
I am calling the updater through QProcess, but if I use process.setArguments(QStringList() << "--checkupdates"); the argument isn't passed down to the process.
Example:
This passes the arguments and the updater checks for updates:QProcess process; process.start(updaterPath, QStringList() << "--checkupdates");
This doesn't pass the arguments and the updater's UI is opened:
QProcess process; process.setArguments(QStringList() << "--checkupdates"); process.start(updaterPath);
From docs:
void QProcess::setArguments(const QStringList &arguments)Set the arguments to pass to the called program when starting the process. This function must be called before start().
This happens on Windows 10 x64, application built with Qt 5.12.6, MSVC2017 x32 compiler.
-
see the documentation for QString::start(const QString &command, QIODevice::OpenMode mode = ReadWrite)
-
@adutzu89
@Christian-Ehrlicher is telling you that thevoid QProcess::start(const QString &command, QIODevice::OpenMode mode = ReadWrite)
you are failing with requires a single string argument of the complete command line. It does not append any arguments you have set withQProcess::setArguments()
.Only the void QProcess::start(QIODevice::OpenMode mode = ReadWrite) overload, and bool QProcess::startDetached(qint64 *pid = nullptr) refer to QStringList QProcess::arguments() const, and they require you to use setProgram() for the executable path.
I think the docs might be clearer on this, it can be easy to misunderstand which spawners are using
setArguments()
and which are not. You just have to read carefully and try them. -
There is even a macro which prevents the use of this somewhat strange function: QT_NO_PROCESS_COMBINED_ARGUMENT_START
-
@Christian-Ehrlicher
There is indeed, but that (enabled or not) would not make it use thesetArguments()
which is the user's expectation.EDIT Hmm:
Disables the QProcess::start() overload taking a single string. In most cases where it is used, the user intends for the first argument to be treated atomically as per the other overload.
and
In virtually all cases, using the other overload is the preferred method.
Frankly, I find this even more confusing than before! :)
I think we're saying: if you use
setArguments()
you then need to dostart()
viasetProgram()
.... -
@Christian-Ehrlicher & @JonB , ty for your answers, it's clear now.