19#if __has_include(<paths.h>)
100 auto it =
other.vars.constBegin();
101 const auto end =
other.vars.constEnd();
107 auto nit =
other.nameMap.constBegin();
108 const auto nend =
other.nameMap.constEnd();
109 for ( ; nit != nend; ++nit)
110 nameMap.insert(nit.key(), nit.value());
375#if QT_CONFIG(process)
377void QProcessPrivate::Channel::clear()
382 process->stdinChannel.type =
Normal;
383 process->stdinChannel.process =
nullptr;
387 process->stdoutChannel.type =
Normal;
388 process->stdoutChannel.process =
nullptr;
958QProcessPrivate::QProcessPrivate()
969QProcessPrivate::~QProcessPrivate()
971 if (stdinChannel.process)
972 stdinChannel.process->stdoutChannel.clear();
973 if (stdoutChannel.process)
974 stdoutChannel.process->stdinChannel.clear();
980void QProcessPrivate::setError(QProcess::ProcessError
error,
const QString &description)
982 processError =
error;
985 case QProcess::FailedToStart:
986 errorString = QProcess::tr(
"Process failed to start");
988 case QProcess::Crashed:
991 case QProcess::Timedout:
992 errorString = QProcess::tr(
"Process operation timed out");
994 case QProcess::ReadError:
995 errorString = QProcess::tr(
"Error reading from process");
997 case QProcess::WriteError:
998 errorString = QProcess::tr(
"Error writing to process");
1000 case QProcess::UnknownError:
1012void QProcessPrivate::setErrorAndEmit(QProcess::ProcessError
error,
const QString &description)
1017 emit q->errorOccurred(QProcess::ProcessError(processError));
1023bool QProcessPrivate::openChannels()
1026 if (inputChannelMode == QProcess::ForwardedInputChannel) {
1027 if (stdinChannel.type != Channel::Normal)
1028 qWarning(
"QProcess::openChannels: Inconsistent stdin channel configuration");
1029 }
else if (!openChannel(stdinChannel)) {
1034 if (processChannelMode == QProcess::ForwardedChannels
1035 || processChannelMode == QProcess::ForwardedOutputChannel) {
1036 if (stdoutChannel.type != Channel::Normal)
1037 qWarning(
"QProcess::openChannels: Inconsistent stdout channel configuration");
1038 }
else if (!openChannel(stdoutChannel)) {
1043 if (processChannelMode == QProcess::ForwardedChannels
1044 || processChannelMode == QProcess::ForwardedErrorChannel
1045 || processChannelMode == QProcess::MergedChannels) {
1046 if (stderrChannel.type != Channel::Normal)
1047 qWarning(
"QProcess::openChannels: Inconsistent stderr channel configuration");
1048 }
else if (!openChannel(stderrChannel)) {
1058void QProcessPrivate::closeChannels()
1060 closeChannel(&stdoutChannel);
1061 closeChannel(&stderrChannel);
1062 closeChannel(&stdinChannel);
1068bool QProcessPrivate::openChannelsForDetached()
1071 bool needToOpen = (stdinChannel.type == Channel::Redirect
1072 || stdinChannel.type == Channel::PipeSink);
1073 if (stdinChannel.type != Channel::Normal
1075 || inputChannelMode == QProcess::ForwardedInputChannel)) {
1076 qWarning(
"QProcess::openChannelsForDetached: Inconsistent stdin channel configuration");
1078 if (needToOpen && !openChannel(stdinChannel))
1082 needToOpen = (stdoutChannel.type == Channel::Redirect
1083 || stdoutChannel.type == Channel::PipeSource);
1084 if (stdoutChannel.type != Channel::Normal
1086 || processChannelMode == QProcess::ForwardedChannels
1087 || processChannelMode == QProcess::ForwardedOutputChannel)) {
1088 qWarning(
"QProcess::openChannelsForDetached: Inconsistent stdout channel configuration");
1090 if (needToOpen && !openChannel(stdoutChannel))
1094 needToOpen = (stderrChannel.type == Channel::Redirect);
1095 if (stderrChannel.type != Channel::Normal
1097 || processChannelMode == QProcess::ForwardedChannels
1098 || processChannelMode == QProcess::ForwardedErrorChannel
1099 || processChannelMode == QProcess::MergedChannels)) {
1100 qWarning(
"QProcess::openChannelsForDetached: Inconsistent stderr channel configuration");
1102 if (needToOpen && !openChannel(stderrChannel))
1112bool QProcessPrivate::tryReadFromChannel(Channel *
channel)
1122 QProcess::ProcessChannel channelIdx = (
channel == &stdoutChannel
1123 ? QProcess::StandardOutput
1124 : QProcess::StandardError);
1125 Q_ASSERT(readBuffers.size() >
int(channelIdx));
1131 if (readBytes == -2) {
1135 if (readBytes == -1) {
1136 setErrorAndEmit(QProcess::ReadError);
1137#if defined QPROCESS_DEBUG
1138 qDebug(
"QProcessPrivate::tryReadFromChannel(%d), failed to read from the process",
1139 int(
channel - &stdinChannel));
1143 if (readBytes == 0) {
1146#if defined QPROCESS_DEBUG
1147 qDebug(
"QProcessPrivate::tryReadFromChannel(%d), 0 bytes available",
1148 int(
channel - &stdinChannel));
1152#if defined QPROCESS_DEBUG
1153 qDebug(
"QProcessPrivate::tryReadFromChannel(%d), read %lld bytes from the process' output",
1154 int(
channel - &stdinChannel), readBytes);
1164 bool didRead =
false;
1165 if (currentReadChannel == channelIdx) {
1167 if (!emittedReadyRead) {
1169 emit q->readyRead();
1172 emit q->channelReadyRead(
int(channelIdx));
1173 if (channelIdx == QProcess::StandardOutput)
1174 emit q->readyReadStandardOutput(QProcess::QPrivateSignal());
1176 emit q->readyReadStandardError(QProcess::QPrivateSignal());
1183bool QProcessPrivate::_q_canReadStandardOutput()
1185 return tryReadFromChannel(&stdoutChannel);
1191bool QProcessPrivate::_q_canReadStandardError()
1193 return tryReadFromChannel(&stderrChannel);
1199void QProcessPrivate::_q_processDied()
1201#if defined QPROCESS_DEBUG
1202 qDebug(
"QProcessPrivate::_q_processDied()");
1211 _q_canReadStandardOutput();
1212 _q_canReadStandardError();
1218 if (processState != QProcess::NotRunning)
1225void QProcessPrivate::processFinished()
1228#if defined QPROCESS_DEBUG
1229 qDebug(
"QProcessPrivate::processFinished()");
1240 if (exitStatus == QProcess::CrashExit)
1241 setErrorAndEmit(QProcess::Crashed);
1244 emit q->readChannelFinished();
1249 emit q->finished(exitCode, QProcess::ExitStatus(exitStatus));
1251#if defined QPROCESS_DEBUG
1252 qDebug(
"QProcessPrivate::processFinished(): process is dead");
1259bool QProcessPrivate::_q_startupNotification()
1262#if defined QPROCESS_DEBUG
1263 qDebug(
"QProcessPrivate::startupNotification()");
1268 q->setProcessState(QProcess::Running);
1269 emit q->started(QProcess::QPrivateSignal());
1273 q->setProcessState(QProcess::NotRunning);
1274 setErrorAndEmit(QProcess::FailedToStart,
errorMessage);
1285void QProcessPrivate::closeWriteChannel()
1287#if defined QPROCESS_DEBUG
1288 qDebug(
"QProcessPrivate::closeWriteChannel()");
1291 closeChannel(&stdinChannel);
1300#if defined QPROCESS_DEBUG
1311QProcess::~QProcess()
1314 if (
d->processState != NotRunning) {
1331QProcess::ProcessChannelMode QProcess::processChannelMode()
const
1333 Q_D(
const QProcess);
1334 return ProcessChannelMode(
d->processChannelMode);
1348void QProcess::setProcessChannelMode(ProcessChannelMode
mode)
1351 d->processChannelMode =
mode;
1361QProcess::InputChannelMode QProcess::inputChannelMode()
const
1363 Q_D(
const QProcess);
1364 return InputChannelMode(
d->inputChannelMode);
1376void QProcess::setInputChannelMode(InputChannelMode
mode)
1379 d->inputChannelMode =
mode;
1387QProcess::ProcessChannel QProcess::readChannel()
const
1389 Q_D(
const QProcess);
1390 return ProcessChannel(
d->currentReadChannel);
1401void QProcess::setReadChannel(ProcessChannel
channel)
1416void QProcess::closeReadChannel(ProcessChannel
channel)
1420 if (
channel == StandardOutput)
1421 d->stdoutChannel.closed =
true;
1423 d->stderrChannel.closed =
true;
1444void QProcess::closeWriteChannel()
1447 d->stdinChannel.closed =
true;
1448 if (bytesToWrite() == 0)
1449 d->closeWriteChannel();
1514 d->stdoutChannel.append =
mode == Append;
1541 d->stderrChannel.append =
mode == Append;
1556void QProcess::setStandardOutputProcess(QProcess *
destination)
1558 QProcessPrivate *dfrom = d_func();
1560 dfrom->stdoutChannel.pipeTo(dto);
1561 dto->stdinChannel.pipeFrom(dfrom);
1564#if defined(Q_OS_WIN) || defined(Q_QDOC)
1575QString QProcess::nativeArguments()
const
1577 Q_D(
const QProcess);
1578 return d->nativeArguments;
1614QProcess::CreateProcessArgumentModifier QProcess::createProcessArgumentsModifier()
const
1616 Q_D(
const QProcess);
1617 return d->modifyCreateProcessArgs;
1631void QProcess::setCreateProcessArgumentsModifier(CreateProcessArgumentModifier modifier)
1634 d->modifyCreateProcessArgs = modifier;
1639#if defined(Q_OS_UNIX) || defined(Q_QDOC)
1650std::function<
void(
void)> QProcess::childProcessModifier()
const
1652 Q_D(
const QProcess);
1653 return d->unixExtras ?
d->unixExtras->childProcessModifier : std::function<void(void)>();
1703void QProcess::setChildProcessModifier(
const std::function<
void(
void)> &modifier)
1707 d->unixExtras.reset(
new QProcessPrivate::UnixExtras);
1708 d->unixExtras->childProcessModifier = modifier;
1761auto QProcess::unixProcessParameters() const noexcept -> UnixProcessParameters
1763 Q_D(
const QProcess);
1764 return d->unixExtras ?
d->unixExtras->processParameters : UnixProcessParameters{};
1785void QProcess::setUnixProcessParameters(
const UnixProcessParameters &
params)
1789 d->unixExtras.reset(
new QProcessPrivate::UnixExtras);
1790 d->unixExtras->processParameters =
params;
1804void QProcess::setUnixProcessParameters(UnixProcessFlags flagsOnly)
1808 d->unixExtras.reset(
new QProcessPrivate::UnixExtras);
1809 d->unixExtras->processParameters = { flagsOnly };
1822QString QProcess::workingDirectory()
const
1824 Q_D(
const QProcess);
1825 return d->workingDirectory;
1835void QProcess::setWorkingDirectory(
const QString &
dir)
1838 d->workingDirectory =
dir;
1847qint64 QProcess::processId()
const
1849 Q_D(
const QProcess);
1851 return d->pid ?
d->pid->dwProcessId : 0;
1862void QProcess::close()
1865 emit aboutToClose();
1866 while (waitForBytesWritten(-1))
1870 d->setWriteChannelCount(0);
1876bool QProcess::isSequential()
const
1883qint64 QProcess::bytesToWrite()
const
1886 return d_func()->pipeWriterBytesToWrite();
1897QProcess::ProcessError QProcess::error()
const
1899 Q_D(
const QProcess);
1900 return ProcessError(
d->processError);
1908QProcess::ProcessState QProcess::state()
const
1910 Q_D(
const QProcess);
1911 return ProcessState(
d->processState);
1928void QProcess::setEnvironment(
const QStringList &environment)
1944 Q_D(
const QProcess);
1945 return d->environment.toStringList();
1964 d->environment = environment;
1978 Q_D(
const QProcess);
1979 return d->environment;
2004bool QProcess::waitForStarted(
int msecs)
2007 if (
d->processState == QProcess::Starting)
2010 return d->processState == QProcess::Running;
2015bool QProcess::waitForReadyRead(
int msecs)
2019 if (
d->processState == QProcess::NotRunning)
2021 if (
d->currentReadChannel == QProcess::StandardOutput &&
d->stdoutChannel.closed)
2023 if (
d->currentReadChannel == QProcess::StandardError &&
d->stderrChannel.closed)
2027 if (
d->processState == QProcess::Starting) {
2028 bool started =
d->waitForStarted(
deadline);
2038bool QProcess::waitForBytesWritten(
int msecs)
2041 if (
d->processState == QProcess::NotRunning)
2045 if (
d->processState == QProcess::Starting) {
2046 bool started =
d->waitForStarted(
deadline);
2051 return d->waitForBytesWritten(
deadline);
2073bool QProcess::waitForFinished(
int msecs)
2076 if (
d->processState == QProcess::NotRunning)
2080 if (
d->processState == QProcess::Starting) {
2081 bool started =
d->waitForStarted(
deadline);
2094void QProcess::setProcessState(ProcessState
state)
2097 if (
d->processState ==
state)
2100 emit stateChanged(
state, QPrivateSignal());
2103#if QT_VERSION < QT_VERSION_CHECK(7,0,0)
2107auto QProcess::setupChildProcess() -> Use_setChildProcessModifier_Instead
2109 Q_UNREACHABLE_RETURN({});
2121 if (
d->processState == QProcess::NotRunning)
2135 ProcessChannel tmp = readChannel();
2136 setReadChannel(StandardOutput);
2138 setReadChannel(tmp);
2153 if (
d->processChannelMode == MergedChannels) {
2154 qWarning(
"QProcess::readAllStandardError: Called with MergedChannels");
2156 ProcessChannel tmp = readChannel();
2157 setReadChannel(StandardError);
2159 setReadChannel(tmp);
2198 if (
d->processState != NotRunning) {
2199 qWarning(
"QProcess::start: Process is already running");
2203 d->setErrorAndEmit(QProcess::FailedToStart,
tr(
"No program defined"));
2222void QProcess::start(OpenMode
mode)
2225 if (
d->processState != NotRunning) {
2226 qWarning(
"QProcess::start: Process is already running");
2229 if (
d->program.isEmpty()) {
2230 d->setErrorAndEmit(QProcess::FailedToStart,
tr(
"No program defined"));
2271void QProcess::startCommand(
const QString &command, OpenMode
mode)
2325bool QProcess::startDetached(
qint64 *pid)
2328 if (
d->processState != NotRunning) {
2329 qWarning(
"QProcess::startDetached: Process is already running");
2332 if (
d->program.isEmpty()) {
2333 d->setErrorAndEmit(QProcess::FailedToStart,
tr(
"No program defined"));
2336 return d->startDetached(pid);
2350bool QProcess::open(OpenMode
mode)
2353 if (
d->processState != NotRunning) {
2354 qWarning(
"QProcess::start: Process is already running");
2357 if (
d->program.isEmpty()) {
2358 qWarning(
"QProcess::start: program not set");
2366void QProcessPrivate::start(QIODevice::OpenMode
mode)
2369#if defined QPROCESS_DEBUG
2373 if (stdinChannel.type != QProcessPrivate::Channel::Normal)
2375 if (stdoutChannel.type != QProcessPrivate::Channel::Normal &&
2376 (stderrChannel.type != QProcessPrivate::Channel::Normal ||
2377 processChannelMode == QProcess::MergedChannels))
2382 if (stdoutChannel.type == QProcessPrivate::Channel::Normal)
2383 q->setStandardOutputFile(
q->nullDevice());
2384 if (stderrChannel.type == QProcessPrivate::Channel::Normal
2385 && processChannelMode != QProcess::MergedChannels)
2386 q->setStandardErrorFile(
q->nullDevice());
2389 q->QIODevice::open(
mode);
2391 if (
q->isReadable() && processChannelMode != QProcess::MergedChannels)
2392 setReadChannelCount(2);
2394 stdinChannel.closed =
false;
2395 stdoutChannel.closed =
false;
2396 stderrChannel.closed =
false;
2399 exitStatus = QProcess::NormalExit;
2400 processError = QProcess::UnknownError;
2419 bool inQuote =
false;
2424 for (
int i = 0;
i < command.
size(); ++
i) {
2425 if (command.
at(
i) == u
'"') {
2427 if (quoteCount == 3) {
2430 tmp += command.
at(
i);
2435 if (quoteCount == 1)
2445 tmp += command.
at(
i);
2461QString QProcess::program()
const
2463 Q_D(
const QProcess);
2483 if (
d->processState != NotRunning) {
2484 qWarning(
"QProcess::setProgram: Process is already running");
2499 Q_D(
const QProcess);
2500 return d->arguments;
2514 if (
d->processState != NotRunning) {
2515 qWarning(
"QProcess::setProgram: Process is already running");
2537void QProcess::terminate()
2540 d->terminateProcess();
2551void QProcess::kill()
2562int QProcess::exitCode()
const
2564 Q_D(
const QProcess);
2577QProcess::ExitStatus QProcess::exitStatus()
const
2579 Q_D(
const QProcess);
2580 return ExitStatus(
d->exitStatus);
2603 process.setProcessChannelMode(ForwardedChannels);
2605 if (!process.waitForFinished(-1) || process.error() == FailedToStart)
2607 return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1;
2631 const QString &workingDirectory,
2637 process.setWorkingDirectory(workingDirectory);
2638 return process.startDetached(pid);
2698#elif defined(_PATH_DEVNULL)
2709#include "moc_qprocess.cpp"
IOBluetoothL2CAPChannel * channel
constexpr bool isSpace() const noexcept
Returns true if the character is a separator character (Separator_* categories or certain code points...
static QString toNativeSeparators(const QString &pathName)
\inmodule QtCore \reentrant
virtual qint64 bytesToWrite() const
For buffered devices, this function returns the number of bytes waiting to be written.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
void setCurrentReadChannel(int channel)
const_iterator constBegin() const noexcept
const_iterator constEnd() const noexcept
const_iterator ConstIterator
iterator insert(const Key &key, const T &value)
bool contains(const Key &key) const
const_iterator cend() const
size_type remove(const Key &key)
const_iterator cbegin() const
const_iterator constFind(const Key &key) const
const_iterator constBegin() const
const_iterator constEnd() const
Value prepareValue(const QString &value) const
static QProcessEnvironment fromList(const QStringList &list)
Key prepareName(const QString &name) const
QString valueToString(const Value &value) const
void insert(const QProcessEnvironmentPrivate &other)
QString nameToString(const Key &name) const
QStringList toList() const
QProcessEnvironment & operator=(const QProcessEnvironment &other)
Copies the contents of the other QProcessEnvironment object into this one.
QString value(const QString &name, const QString &defaultValue=QString()) const
Searches this QProcessEnvironment object for a variable identified by name and returns its value.
void remove(const QString &name)
Removes the environment variable identified by name from this QProcessEnvironment object.
QStringList toStringList() const
Converts this QProcessEnvironment object into a list of strings, one for each environment variable th...
void insert(const QString &name, const QString &value)
Inserts the environment variable of name name and contents value into this QProcessEnvironment object...
bool isEmpty() const
Returns true if this QProcessEnvironment object is empty: that is there are no key=value pairs set.
bool inheritsFromParent() const
Returns true if this QProcessEnvironment was constructed using {QProcessEnvironment::InheritFromParen...
bool contains(const QString &name) const
Returns true if the environment variable of name name is found in this QProcessEnvironment object.
QProcessEnvironment()
Creates a new QProcessEnvironment object.
void clear()
Removes all key=value pairs from this QProcessEnvironment object, making it empty.
Initialization
This enum contains a token that is used to disambiguate constructors.
bool operator==(const QProcessEnvironment &other) const
Returns true if this and the other QProcessEnvironment objects are equal.
~QProcessEnvironment()
Frees the resources associated with this QProcessEnvironment object.
static QProcessEnvironment systemEnvironment()
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
const T * constData() const noexcept
Returns a const pointer to the shared data object.
T * data()
Returns a pointer to the shared data object.
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
constexpr QChar at(qsizetype n) const noexcept
Returns the character at position n in this string view.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void clear()
Clears the contents of the string and makes it null.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QSet< QString >::iterator it
QList< QVariant > arguments
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char * destination
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static ControlElement< T > * ptr(QWidget *widget)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
GLbitfield GLuint readBuffer
static void setError(QJsonObject *response, const QString &msg)
#define QRINGBUFFER_CHUNKSIZE
#define QStringLiteral(str)
static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)
QDeadlineTimer deadline(30s)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent