From 068baa9bb6d526cccc0c8bc7cdbb84bbdf137f95 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 5 Jun 2015 16:57:18 +0200 Subject: add a way to modify CreateProcess parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ChangeLog][QtCore][QProcess] Added method setCreateProcessArgumentsModifier to QProcess on Windows to enable users to intercept and modify CreateProcess parameters. With such a modifier, calling code can decide whether to inherit handles, modify the STARTUPINFO struct, and pass its own combination of process flags to CreateProcess. Task-number: QTBUG-390 Task-number: QTBUG-6917 Task-number: QTBUG-9350 Task-number: QTBUG-24619 Change-Id: I14757dbbacfebb1c89f52402d36fba0ba9c45f3a Reviewed-by: Björn Breitmeyer Reviewed-by: Thiago Macieira --- src/corelib/io/qprocess.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'src/corelib/io/qprocess.cpp') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 952116b9db..315142aabe 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -743,6 +743,47 @@ void QProcessPrivate::Channel::clear() \sa exitStatus() */ +/*! + \typedef QProcess::CreateProcessArgumentModifier + \note This typedef is only available on desktop Windows and Windows CE. + + On Windows, QProcess uses the Win32 API function \c CreateProcess to + start child processes. While QProcess provides a comfortable way to start + processes without worrying about platform + details, it is in some cases desirable to fine-tune the parameters that are + passed to \c CreateProcess. This is done by defining a + \c CreateProcessArgumentModifier function and passing it to + \c setCreateProcessArgumentsModifier. + + A \c CreateProcessArgumentModifier function takes one parameter: a pointer + to a \c CreateProcessArguments struct. The members of this struct will be + passed to \c CreateProcess after the \c CreateProcessArgumentModifier + function is called. + + The following example demonstrates how to pass custom flags to + \c CreateProcess. + When starting a console process B from a console process A, QProcess will + reuse the console window of process A for process B by default. In this + example, a new console window with a custom color scheme is created for the + child process B instead. + + \snippet qprocess/qprocess-createprocessargumentsmodifier.cpp 0 + + \sa QProcess::CreateProcessArguments + \sa setCreateProcessArgumentsModifier() +*/ + +/*! + \class QProcess::CreateProcessArguments + \note This struct is only available on the Windows platform. + + This struct is a representation of all parameters of the Windows API + function \c CreateProcess. It is used as parameter for + \c CreateProcessArgumentModifier functions. + + \sa QProcess::CreateProcessArgumentModifier +*/ + /*! \fn void QProcess::error(QProcess::ProcessError error) \obsolete @@ -1563,6 +1604,39 @@ void QProcess::setNativeArguments(const QString &arguments) d->nativeArguments = arguments; } +/*! + \since 5.7 + + Returns a previously set \c CreateProcess modifier function. + + \note This function is available only on the Windows platform. + + \sa setCreateProcessArgumentsModifier() + \sa QProcess::CreateProcessArgumentModifier +*/ +QProcess::CreateProcessArgumentModifier QProcess::createProcessArgumentsModifier() const +{ + Q_D(const QProcess); + return d->modifyCreateProcessArgs; +} + +/*! + \since 5.7 + + Sets the \a modifier for the \c CreateProcess Win32 API call. + Pass \c QProcess::CreateProcessArgumentModifier() to remove a previously set one. + + \note This function is available only on the Windows platform and requires + C++11. + + \sa QProcess::CreateProcessArgumentModifier +*/ +void QProcess::setCreateProcessArgumentsModifier(CreateProcessArgumentModifier modifier) +{ + Q_D(QProcess); + d->modifyCreateProcessArgs = modifier; +} + #endif /*! -- cgit v1.2.3