diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2020-02-29 14:47:43 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-09-08 21:00:29 -0700 |
commit | 7e93870401852623b316a9e707baf67cbaa6d722 (patch) | |
tree | f26caef521e35e3c3b3827794ffea832d4fd0491 /src/corelib/io/qprocess.h | |
parent | 3deb154d2207c5b38675ee75b4a843a100abf6a9 (diff) |
QProcess/Unix: introduce setChildProcessModifier()
[ChangeLog][Source-Incompatible Changes] QProcess::setupChildProcess()
was removed. To execute code in a child process, use
QProcess::setChildProcessModifier()
[ChangeLog][QtCore][QProcess] Added setChildProcessModifier() function
with which one can provide code to be run in the Unix child process
between fork() and execve(). With this function, it is no longer
necessary to derive from QProcess in order to execute actions in the
child process.
Another reason is that we can tell whether the std::function carries a
valid target much more easily than we can tell whether QProcess was
overridden.
The setupChildProcess() virtual function does not need to be marked
final, since no overrider could ever return an inaccessible private
class. This also makes sure the error presented to the user is about the
return type, not about attempting to override a final.
Clang:
error: virtual function 'f' has a different return type ('void') than the function it overrides (which has return type 'QProcess::Use_setChildProcessModifier_Instead')
GCC:
error: conflicting return type specified for 'virtual void MyProcess::setupChildProcess()'
note: overridden function is 'virtual QProcess::Use_setChildProcessModifier_Instead QProcess::setupChildProcess()'
ICC:
error: return type is neither identical to nor covariant with return type "QProcess::Use_setChildProcessModifier_Instead" of overridden virtual function "QProcess::setupChildProcess"
MSVC is not relevant since it doesn't compile to Unix.
Change-Id: Ia8b65350cd5d49debca9fffd15f801161363aea7
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io/qprocess.h')
-rw-r--r-- | src/corelib/io/qprocess.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index 9e497c3871..77980e012c 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -205,6 +205,10 @@ public: CreateProcessArgumentModifier createProcessArgumentsModifier() const; void setCreateProcessArgumentsModifier(CreateProcessArgumentModifier modifier); #endif // Q_OS_WIN || Q_CLANG_QDOC +#if defined(Q_OS_UNIX) || defined(Q_CLANG_QDOC) + std::function<void(void)> childProcessModifier() const; + void setChildProcessModifier(const std::function<void(void)> &modifier); +#endif QString workingDirectory() const; void setWorkingDirectory(const QString &dir); @@ -263,8 +267,6 @@ Q_SIGNALS: protected: void setProcessState(ProcessState state); - virtual void setupChildProcess(); - // QIODevice qint64 readData(char *data, qint64 maxlen) override; qint64 writeData(const char *data, qint64 len) override; @@ -273,6 +275,15 @@ private: Q_DECLARE_PRIVATE(QProcess) Q_DISABLE_COPY(QProcess) +#if QT_VERSION < QT_VERSION_CHECK(7,0,0) + // ### Qt7: Remove this struct and the virtual function; they're here only + // to cause build errors in Qt 5 code that wasn't updated to Qt 6's + // setChildProcessModifier() + struct Use_setChildProcessModifier_Instead {}; + QT_DEPRECATED_X("Use setChildProcessModifier() instead") + virtual Use_setChildProcessModifier_Instead setupChildProcess(); +#endif + Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardOutput()) Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardError()) Q_PRIVATE_SLOT(d_func(), bool _q_canWrite()) |