Qt 4.8
qprocess.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //#define QPROCESS_DEBUG
43 
44 #if defined QPROCESS_DEBUG
45 #include <qdebug.h>
46 #include <qstring.h>
47 #include <ctype.h>
48 #if !defined(Q_OS_WINCE)
49 #include <errno.h>
50 #endif
51 
53 /*
54  Returns a human readable representation of the first \a len
55  characters in \a data.
56 */
57 static QByteArray qt_prettyDebug(const char *data, int len, int maxSize)
58 {
59  if (!data) return "(null)";
60  QByteArray out;
61  for (int i = 0; i < len && i < maxSize; ++i) {
62  char c = data[i];
63  if (isprint(c)) {
64  out += c;
65  } else switch (c) {
66  case '\n': out += "\\n"; break;
67  case '\r': out += "\\r"; break;
68  case '\t': out += "\\t"; break;
69  default:
70  char buf[5];
71  qsnprintf(buf, sizeof(buf), "\\%3o", c);
72  buf[4] = '\0';
73  out += QByteArray(buf);
74  }
75  }
76 
77  if (len < maxSize)
78  out += "...";
79 
80  return out;
81 }
82 
84 
85 #endif
86 
87 #include "qprocess.h"
88 #include "qprocess_p.h"
89 
90 #include <qbytearray.h>
91 #include <qelapsedtimer.h>
92 #include <qcoreapplication.h>
93 #include <qsocketnotifier.h>
94 #include <qtimer.h>
95 
96 #ifdef Q_WS_WIN
97 #include <private/qwineventnotifier_p.h>
98 #endif
99 
100 #ifdef Q_OS_SYMBIAN
101 #include <e32std.h>
102 #endif
103 
104 #ifndef QT_NO_PROCESS
105 
107 
151 {
152  QStringList result;
153  result.reserve(hash.size());
155  end = hash.constEnd();
156  for ( ; it != end; ++it) {
157  QString data = nameToString(it.key());
158  QString value = valueToString(it.value());
159  data.reserve(data.length() + value.length() + 1);
160  data.append(QLatin1Char('='));
161  data.append(value);
162  result << data;
163  }
164  return result;
165 }
166 
168 {
171  end = list.constEnd();
172  for ( ; it != end; ++it) {
173  int pos = it->indexOf(QLatin1Char('='));
174  if (pos < 1)
175  continue;
176 
177  QString value = it->mid(pos + 1);
178  QString name = *it;
179  name.truncate(pos);
180  env.insert(name, value);
181  }
182  return env;
183 }
184 
186 {
187  QStringList result;
188  result.reserve(hash.size());
190  end = hash.constEnd();
191  for ( ; it != end; ++it)
192  result << nameToString(it.key());
193  return result;
194 }
195 
197 {
199  end = other.hash.constEnd();
200  for ( ; it != end; ++it)
201  hash.insert(it.key(), it.value());
202 
203 #ifdef Q_OS_UNIX
205  nend = other.nameMap.constEnd();
206  for ( ; nit != nend; ++nit)
207  nameMap.insert(nit.key(), nit.value());
208 #endif
209 }
210 
217  : d(0)
218 {
219 }
220 
225 {
226 }
227 
232  : d(other.d)
233 {
234 }
235 
241 {
242  d = other.d;
243  return *this;
244 }
245 
267 {
268  if (d == other.d)
269  return true;
270  if (d && other.d) {
272  return d->hash == other.d->hash;
273  }
274  return false;
275 }
276 
284 {
285  // Needs no locking, as no hash nodes are accessed
286  return d ? d->hash.isEmpty() : true;
287 }
288 
296 {
297  if (d)
298  d->hash.clear();
299  // Unix: Don't clear d->nameMap, as the environment is likely to be
300  // re-populated with the same keys again.
301 }
302 
314 {
315  if (!d)
316  return false;
318  return d->hash.contains(d->prepareName(name));
319 }
320 
338 {
339  // our re-impl of detach() detaches from null
340  d.detach(); // detach before prepareName()
341  d->hash.insert(d->prepareName(name), d->prepareValue(value));
342 }
343 
356 {
357  if (d) {
358  d.detach(); // detach before prepareName()
359  d->hash.remove(d->prepareName(name));
360  }
361 }
362 
374 QString QProcessEnvironment::value(const QString &name, const QString &defaultValue) const
375 {
376  if (!d)
377  return defaultValue;
378 
381  if (it == d->hash.constEnd())
382  return defaultValue;
383 
384  return d->valueToString(it.value());
385 }
386 
401 {
402  if (!d)
403  return QStringList();
405  return d->toList();
406 }
407 
418 {
419  if (!d)
420  return QStringList();
422  return d->keys();
423 }
424 
436 {
437  if (!e.d)
438  return;
439 
440  // our re-impl of detach() detaches from null
442  d->insert(*e.d);
443 }
444 
446 {
447  switch (type) {
448  case PipeSource:
449  Q_ASSERT(process);
450  process->stdinChannel.type = Normal;
451  process->stdinChannel.process = 0;
452  break;
453  case PipeSink:
454  Q_ASSERT(process);
455  process->stdoutChannel.type = Normal;
456  process->stdoutChannel.process = 0;
457  break;
458  }
459 
460  type = Normal;
461  file.clear();
462  process = 0;
463 }
464 
821 {
822  processChannel = QProcess::StandardOutput;
823  processChannelMode = QProcess::SeparateChannels;
824  processError = QProcess::UnknownError;
825  processState = QProcess::NotRunning;
826  pid = 0;
827  sequenceNumber = 0;
828  exitCode = 0;
829  exitStatus = QProcess::NormalExit;
830  startupSocketNotifier = 0;
831  deathNotifier = 0;
832  notifier = 0;
833  pipeWriter = 0;
834  childStartedPipe[0] = INVALID_Q_PIPE;
835  childStartedPipe[1] = INVALID_Q_PIPE;
836  deathPipe[0] = INVALID_Q_PIPE;
837  deathPipe[1] = INVALID_Q_PIPE;
838  exitCode = 0;
839  crashed = false;
840  dying = false;
841  emittedReadyRead = false;
842  emittedBytesWritten = false;
843 #ifdef Q_WS_WIN
844  pipeWriter = 0;
845  processFinishedNotifier = 0;
846 #endif // Q_WS_WIN
847 #ifdef Q_OS_UNIX
848  serial = 0;
849 #endif
850 #ifdef Q_OS_SYMBIAN
851  symbianProcess = NULL;
852  processLaunched = false;
853 #endif
854 }
855 
859 {
860  if (stdinChannel.process)
861  stdinChannel.process->stdoutChannel.clear();
862  if (stdoutChannel.process)
863  stdoutChannel.process->stdinChannel.clear();
864 }
865 
869 {
870  q_func()->setProcessState(QProcess::NotRunning);
871 #ifdef Q_OS_WIN
872  if (pid) {
873  CloseHandle(pid->hThread);
874  CloseHandle(pid->hProcess);
875  delete pid;
876  pid = 0;
877  }
878  if (processFinishedNotifier) {
879  processFinishedNotifier->setEnabled(false);
880  qDeleteInEventHandler(processFinishedNotifier);
881  processFinishedNotifier = 0;
882  }
883 
884 #endif
885  pid = 0;
886  sequenceNumber = 0;
887  dying = false;
888 
889  if (stdoutChannel.notifier) {
890  stdoutChannel.notifier->setEnabled(false);
891  qDeleteInEventHandler(stdoutChannel.notifier);
892  stdoutChannel.notifier = 0;
893  }
894  if (stderrChannel.notifier) {
895  stderrChannel.notifier->setEnabled(false);
896  qDeleteInEventHandler(stderrChannel.notifier);
897  stderrChannel.notifier = 0;
898  }
899  if (stdinChannel.notifier) {
900  stdinChannel.notifier->setEnabled(false);
901  qDeleteInEventHandler(stdinChannel.notifier);
902  stdinChannel.notifier = 0;
903  }
904  if (startupSocketNotifier) {
905  startupSocketNotifier->setEnabled(false);
906  qDeleteInEventHandler(startupSocketNotifier);
907  startupSocketNotifier = 0;
908  }
909  if (deathNotifier) {
910  deathNotifier->setEnabled(false);
911  qDeleteInEventHandler(deathNotifier);
912  deathNotifier = 0;
913  }
914  if (notifier) {
915  qDeleteInEventHandler(notifier);
916  notifier = 0;
917  }
918  destroyPipe(stdoutChannel.pipe);
919  destroyPipe(stderrChannel.pipe);
920  destroyPipe(stdinChannel.pipe);
921  destroyPipe(childStartedPipe);
922  destroyPipe(deathPipe);
923 #ifdef Q_OS_UNIX
924  serial = 0;
925 #endif
926 #ifdef Q_OS_SYMBIAN
927  if (symbianProcess) {
928  symbianProcess->Close();
929  delete symbianProcess;
930  symbianProcess = NULL;
931  }
932 #endif
933 }
934 
938 {
939  Q_Q(QProcess);
940  qint64 available = bytesAvailableFromStdout();
941  if (available == 0) {
942  if (stdoutChannel.notifier)
943  stdoutChannel.notifier->setEnabled(false);
944  destroyPipe(stdoutChannel.pipe);
945 #if defined QPROCESS_DEBUG
946  qDebug("QProcessPrivate::canReadStandardOutput(), 0 bytes available");
947 #endif
948  return false;
949  }
950 
951  char *ptr = outputReadBuffer.reserve(available);
952  qint64 readBytes = readFromStdout(ptr, available);
953  if (readBytes == -1) {
954  processError = QProcess::ReadError;
955  q->setErrorString(QProcess::tr("Error reading from process"));
956  emit q->error(processError);
957 #if defined QPROCESS_DEBUG
958  qDebug("QProcessPrivate::canReadStandardOutput(), failed to read from the process");
959 #endif
960  return false;
961  }
962 #if defined QPROCESS_DEBUG
963  qDebug("QProcessPrivate::canReadStandardOutput(), read %d bytes from the process' output",
964  int(readBytes));
965 #endif
966 
967  if (stdoutChannel.closed) {
968  outputReadBuffer.chop(readBytes);
969  return false;
970  }
971 
972  outputReadBuffer.chop(available - readBytes);
973 
974  bool didRead = false;
975  if (readBytes == 0) {
976  if (stdoutChannel.notifier)
977  stdoutChannel.notifier->setEnabled(false);
978  } else if (processChannel == QProcess::StandardOutput) {
979  didRead = true;
980  if (!emittedReadyRead) {
981  emittedReadyRead = true;
982  emit q->readyRead();
983  emittedReadyRead = false;
984  }
985  }
986  emit q->readyReadStandardOutput();
987  return didRead;
988 }
989 
993 {
994  Q_Q(QProcess);
995  qint64 available = bytesAvailableFromStderr();
996  if (available == 0) {
997  if (stderrChannel.notifier)
998  stderrChannel.notifier->setEnabled(false);
999  destroyPipe(stderrChannel.pipe);
1000  return false;
1001  }
1002 
1003  char *ptr = errorReadBuffer.reserve(available);
1004  qint64 readBytes = readFromStderr(ptr, available);
1005  if (readBytes == -1) {
1006  processError = QProcess::ReadError;
1007  q->setErrorString(QProcess::tr("Error reading from process"));
1008  emit q->error(processError);
1009  return false;
1010  }
1011  if (stderrChannel.closed) {
1012  errorReadBuffer.chop(readBytes);
1013  return false;
1014  }
1015 
1016  errorReadBuffer.chop(available - readBytes);
1017 
1018  bool didRead = false;
1019  if (readBytes == 0) {
1020  if (stderrChannel.notifier)
1021  stderrChannel.notifier->setEnabled(false);
1022  } else if (processChannel == QProcess::StandardError) {
1023  didRead = true;
1024  if (!emittedReadyRead) {
1025  emittedReadyRead = true;
1026  emit q->readyRead();
1027  emittedReadyRead = false;
1028  }
1029  }
1030  emit q->readyReadStandardError();
1031  return didRead;
1032 }
1033 
1037 {
1038  Q_Q(QProcess);
1039  if (stdinChannel.notifier)
1040  stdinChannel.notifier->setEnabled(false);
1041 
1042  if (writeBuffer.isEmpty()) {
1043 #if defined QPROCESS_DEBUG
1044  qDebug("QProcessPrivate::canWrite(), not writing anything (empty write buffer).");
1045 #endif
1046  return false;
1047  }
1048 
1049  qint64 written = writeToStdin(writeBuffer.readPointer(),
1050  writeBuffer.nextDataBlockSize());
1051  if (written < 0) {
1052  destroyPipe(stdinChannel.pipe);
1053  processError = QProcess::WriteError;
1054  q->setErrorString(QProcess::tr("Error writing to process"));
1055  emit q->error(processError);
1056  return false;
1057  }
1058 
1059 #if defined QPROCESS_DEBUG
1060  qDebug("QProcessPrivate::canWrite(), wrote %d bytes to the process input", int(written));
1061 #endif
1062 
1063  if (written != 0) {
1064  writeBuffer.free(written);
1065  if (!emittedBytesWritten) {
1066  emittedBytesWritten = true;
1067  emit q->bytesWritten(written);
1068  emittedBytesWritten = false;
1069  }
1070  }
1071  if (stdinChannel.notifier && !writeBuffer.isEmpty())
1072  stdinChannel.notifier->setEnabled(true);
1073  if (writeBuffer.isEmpty() && stdinChannel.closed)
1074  closeWriteChannel();
1075  return true;
1076 }
1077 
1081 {
1082  Q_Q(QProcess);
1083 #if defined QPROCESS_DEBUG
1084  qDebug("QProcessPrivate::_q_processDied()");
1085 #endif
1086 #ifdef Q_OS_UNIX
1087  if (!waitForDeadChild())
1088  return false;
1089 #endif
1090 #ifdef Q_OS_WIN
1091  if (processFinishedNotifier)
1092  processFinishedNotifier->setEnabled(false);
1093 #endif
1094 
1095  // the process may have died before it got a chance to report that it was
1096  // either running or stopped, so we will call _q_startupNotification() and
1097  // give it a chance to emit started() or error(FailedToStart).
1098  if (processState == QProcess::Starting) {
1099  if (!_q_startupNotification())
1100  return true;
1101  }
1102 
1103  if (dying) {
1104  // at this point we know the process is dead. prevent
1105  // reentering this slot recursively by calling waitForFinished()
1106  // or opening a dialog inside slots connected to the readyRead
1107  // signals emitted below.
1108  return true;
1109  }
1110  dying = true;
1111 
1112  // in case there is data in the pipe line and this slot by chance
1113  // got called before the read notifications, call these two slots
1114  // so the data is made available before the process dies.
1115  _q_canReadStandardOutput();
1116  _q_canReadStandardError();
1117 
1118  findExitCode();
1119 
1120  if (crashed) {
1121  exitStatus = QProcess::CrashExit;
1122  processError = QProcess::Crashed;
1123  q->setErrorString(QProcess::tr("Process crashed"));
1124  emit q->error(processError);
1125  }
1126 
1127  bool wasRunning = (processState == QProcess::Running);
1128 
1129  cleanup();
1130 
1131  if (wasRunning) {
1132  // we received EOF now:
1133  emit q->readChannelFinished();
1134  // in the future:
1135  //emit q->standardOutputClosed();
1136  //emit q->standardErrorClosed();
1137 
1138  emit q->finished(exitCode);
1139  emit q->finished(exitCode, exitStatus);
1140  }
1141 #if defined QPROCESS_DEBUG
1142  qDebug("QProcessPrivate::_q_processDied() process is dead");
1143 #endif
1144  return true;
1145 }
1146 
1150 {
1151  Q_Q(QProcess);
1152 #if defined QPROCESS_DEBUG
1153  qDebug("QProcessPrivate::startupNotification()");
1154 #endif
1155 
1156  if (startupSocketNotifier)
1157  startupSocketNotifier->setEnabled(false);
1158  if (processStarted()) {
1159  q->setProcessState(QProcess::Running);
1160  emit q->started();
1161  return true;
1162  }
1163 
1164  q->setProcessState(QProcess::NotRunning);
1165  processError = QProcess::FailedToStart;
1166  emit q->error(processError);
1167 #ifdef Q_OS_UNIX
1168  // make sure the process manager removes this entry
1169  waitForDeadChild();
1170  findExitCode();
1171 #endif
1172  cleanup();
1173  return false;
1174 }
1175 
1179 {
1180 #if defined QPROCESS_DEBUG
1181  qDebug("QProcessPrivate::closeWriteChannel()");
1182 #endif
1183  if (stdinChannel.notifier) {
1184  extern void qDeleteInEventHandler(QObject *o);
1185  stdinChannel.notifier->setEnabled(false);
1186  if (stdinChannel.notifier) {
1187  qDeleteInEventHandler(stdinChannel.notifier);
1188  stdinChannel.notifier = 0;
1189  }
1190  }
1191 #ifdef Q_OS_WIN
1192  // ### Find a better fix, feeding the process little by little
1193  // instead.
1194  flushPipeWriter();
1195 #endif
1196  destroyPipe(stdinChannel.pipe);
1197 }
1198 
1203  : QIODevice(*new QProcessPrivate, parent)
1204 {
1205 #if defined QPROCESS_DEBUG
1206  qDebug("QProcess::QProcess(%p)", parent);
1207 #endif
1208 }
1209 
1217 {
1218  Q_D(QProcess);
1219  if (d->processState != NotRunning) {
1220  qWarning("QProcess: Destroyed while process is still running.");
1221  kill();
1222  waitForFinished();
1223  }
1224 #ifdef Q_OS_UNIX
1225  // make sure the process manager removes this entry
1226  d->findExitCode();
1227 #endif
1228  d->cleanup();
1229 }
1230 
1242 {
1243  return processChannelMode();
1244 }
1245 
1257 {
1258  setProcessChannelMode(mode);
1259 }
1260 
1273 {
1274  Q_D(const QProcess);
1275  return d->processChannelMode;
1276 }
1277 
1293 {
1294  Q_D(QProcess);
1295  d->processChannelMode = mode;
1296 }
1297 
1304 {
1305  Q_D(const QProcess);
1306  return d->processChannel;
1307 }
1308 
1318 {
1319  Q_D(QProcess);
1320  if (d->processChannel != channel) {
1321  QByteArray buf = d->buffer.readAll();
1322  if (d->processChannel == QProcess::StandardOutput) {
1323  for (int i = buf.size() - 1; i >= 0; --i)
1324  d->outputReadBuffer.ungetChar(buf.at(i));
1325  } else {
1326  for (int i = buf.size() - 1; i >= 0; --i)
1327  d->errorReadBuffer.ungetChar(buf.at(i));
1328  }
1329  }
1330  d->processChannel = channel;
1331 }
1332 
1344 {
1345  Q_D(QProcess);
1346 
1347  if (channel == StandardOutput)
1348  d->stdoutChannel.closed = true;
1349  else
1350  d->stderrChannel.closed = true;
1351 }
1352 
1372 {
1373  Q_D(QProcess);
1374  d->stdinChannel.closed = true; // closing
1375  if (d->writeBuffer.isEmpty())
1376  d->closeWriteChannel();
1377 }
1378 
1400 {
1401  Q_D(QProcess);
1402  d->stdinChannel = fileName;
1403 }
1404 
1431 {
1432  Q_ASSERT(mode == Append || mode == Truncate);
1433  Q_D(QProcess);
1434 
1435  d->stdoutChannel = fileName;
1436  d->stdoutChannel.append = mode == Append;
1437 }
1438 
1461 {
1462  Q_ASSERT(mode == Append || mode == Truncate);
1463  Q_D(QProcess);
1464 
1465  d->stderrChannel = fileName;
1466  d->stderrChannel.append = mode == Append;
1467 }
1468 
1485 {
1486  QProcessPrivate *dfrom = d_func();
1487  QProcessPrivate *dto = destination->d_func();
1488  dfrom->stdoutChannel.pipeTo(dto);
1489  dto->stdinChannel.pipeFrom(dfrom);
1490 }
1491 
1492 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
1493 
1508 {
1509  Q_D(const QProcess);
1510  return d->nativeArguments;
1511 }
1512 
1535 {
1536  Q_D(QProcess);
1537  d->nativeArguments = arguments;
1538 }
1539 
1540 #endif
1541 
1552 {
1553  Q_D(const QProcess);
1554  return d->workingDirectory;
1555 }
1556 
1572 {
1573  Q_D(QProcess);
1574  d->workingDirectory = dir;
1575 }
1576 
1582 {
1583  Q_D(const QProcess);
1584  return d->pid;
1585 }
1586 
1597 {
1598  Q_D(const QProcess);
1599  const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
1600  ? &d->errorReadBuffer
1601  : &d->outputReadBuffer;
1602  return readBuffer->canReadLine() || QIODevice::canReadLine();
1603 }
1604 
1611 {
1612  emit aboutToClose();
1613  while (waitForBytesWritten(-1))
1614  ;
1615  kill();
1616  waitForFinished(-1);
1617  QIODevice::close();
1618 }
1619 
1628 bool QProcess::atEnd() const
1629 {
1630  Q_D(const QProcess);
1631  const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
1632  ? &d->errorReadBuffer
1633  : &d->outputReadBuffer;
1634  return QIODevice::atEnd() && (!isOpen() || readBuffer->isEmpty());
1635 }
1636 
1640 {
1641  return true;
1642 }
1643 
1647 {
1648  Q_D(const QProcess);
1649  const QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
1650  ? &d->errorReadBuffer
1651  : &d->outputReadBuffer;
1652 #if defined QPROCESS_DEBUG
1653  qDebug("QProcess::bytesAvailable() == %i (%s)", readBuffer->size(),
1654  (d->processChannel == QProcess::StandardError) ? "stderr" : "stdout");
1655 #endif
1656  return readBuffer->size() + QIODevice::bytesAvailable();
1657 }
1658 
1662 {
1663  Q_D(const QProcess);
1664  qint64 size = d->writeBuffer.size();
1665 #ifdef Q_OS_WIN
1666  size += d->pipeWriterBytesToWrite();
1667 #endif
1668  return size;
1669 }
1670 
1677 {
1678  Q_D(const QProcess);
1679  return d->processError;
1680 }
1681 
1688 {
1689  Q_D(const QProcess);
1690  return d->processState;
1691 }
1692 
1712 {
1714 }
1715 
1732 {
1733  Q_D(const QProcess);
1734  return d->environment.toStringList();
1735 }
1736 
1755 {
1756  Q_D(QProcess);
1757  d->environment = environment;
1758 }
1759 
1776 {
1777  Q_D(const QProcess);
1778  return d->environment;
1779 }
1780 
1801 {
1802  Q_D(QProcess);
1803  if (d->processState == QProcess::Starting)
1804  return d->waitForStarted(msecs);
1805 
1806  return d->processState == QProcess::Running;
1807 }
1808 
1812 {
1813  Q_D(QProcess);
1814 
1815  if (d->processState == QProcess::NotRunning)
1816  return false;
1817  if (d->processChannel == QProcess::StandardOutput && d->stdoutChannel.closed)
1818  return false;
1819  if (d->processChannel == QProcess::StandardError && d->stderrChannel.closed)
1820  return false;
1821  return d->waitForReadyRead(msecs);
1822 }
1823 
1827 {
1828  Q_D(QProcess);
1829  if (d->processState == QProcess::NotRunning)
1830  return false;
1831  if (d->processState == QProcess::Starting) {
1832  QElapsedTimer stopWatch;
1833  stopWatch.start();
1834  bool started = waitForStarted(msecs);
1835  if (!started)
1836  return false;
1837  if (msecs != -1)
1838  msecs -= stopWatch.elapsed();
1839  }
1840 
1841  return d->waitForBytesWritten(msecs);
1842 }
1843 
1864 {
1865  Q_D(QProcess);
1866  if (d->processState == QProcess::NotRunning)
1867  return false;
1868  if (d->processState == QProcess::Starting) {
1869  QElapsedTimer stopWatch;
1870  stopWatch.start();
1871  bool started = waitForStarted(msecs);
1872  if (!started)
1873  return false;
1874  if (msecs != -1)
1875  msecs -= stopWatch.elapsed();
1876  }
1877 
1878  return d->waitForFinished(msecs);
1879 }
1880 
1887 {
1888  Q_D(QProcess);
1889  if (d->processState == state)
1890  return;
1891  d->processState = state;
1892  emit stateChanged(state);
1893 }
1894 
1912 {
1913 }
1914 
1917 qint64 QProcess::readData(char *data, qint64 maxlen)
1918 {
1919  Q_D(QProcess);
1920  QRingBuffer *readBuffer = (d->processChannel == QProcess::StandardError)
1921  ? &d->errorReadBuffer
1922  : &d->outputReadBuffer;
1923 
1924  if (maxlen == 1 && !readBuffer->isEmpty()) {
1925  int c = readBuffer->getChar();
1926  if (c == -1) {
1927 #if defined QPROCESS_DEBUG
1928  qDebug("QProcess::readData(%p \"%s\", %d) == -1",
1929  data, qt_prettyDebug(data, 1, maxlen).constData(), 1);
1930 #endif
1931  return -1;
1932  }
1933  *data = (char) c;
1934 #if defined QPROCESS_DEBUG
1935  qDebug("QProcess::readData(%p \"%s\", %d) == 1",
1936  data, qt_prettyDebug(data, 1, maxlen).constData(), 1);
1937 #endif
1938  return 1;
1939  }
1940 
1941  qint64 bytesToRead = qint64(qMin(readBuffer->size(), (int)maxlen));
1942  qint64 readSoFar = 0;
1943  while (readSoFar < bytesToRead) {
1944  const char *ptr = readBuffer->readPointer();
1945  int bytesToReadFromThisBlock = qMin<qint64>(bytesToRead - readSoFar,
1946  readBuffer->nextDataBlockSize());
1947  memcpy(data + readSoFar, ptr, bytesToReadFromThisBlock);
1948  readSoFar += bytesToReadFromThisBlock;
1949  readBuffer->free(bytesToReadFromThisBlock);
1950  }
1951 
1952 #if defined QPROCESS_DEBUG
1953  qDebug("QProcess::readData(%p \"%s\", %lld) == %lld",
1954  data, qt_prettyDebug(data, readSoFar, 16).constData(), maxlen, readSoFar);
1955 #endif
1956  if (!readSoFar && d->processState == QProcess::NotRunning)
1957  return -1; // EOF
1958  return readSoFar;
1959 }
1960 
1963 qint64 QProcess::writeData(const char *data, qint64 len)
1964 {
1965  Q_D(QProcess);
1966 
1967 #if defined(Q_OS_WINCE)
1968  Q_UNUSED(data);
1969  Q_UNUSED(len);
1970  d->processError = QProcess::WriteError;
1971  setErrorString(tr("Error writing to process"));
1972  emit error(d->processError);
1973  return -1;
1974 #endif
1975 
1976  if (d->stdinChannel.closed) {
1977 #if defined QPROCESS_DEBUG
1978  qDebug("QProcess::writeData(%p \"%s\", %lld) == 0 (write channel closing)",
1979  data, qt_prettyDebug(data, len, 16).constData(), len);
1980 #endif
1981  return 0;
1982  }
1983 
1984  if (len == 1) {
1985  d->writeBuffer.putChar(*data);
1986  if (d->stdinChannel.notifier)
1987  d->stdinChannel.notifier->setEnabled(true);
1988 #if defined QPROCESS_DEBUG
1989  qDebug("QProcess::writeData(%p \"%s\", %lld) == 1 (written to buffer)",
1990  data, qt_prettyDebug(data, len, 16).constData(), len);
1991 #endif
1992  return 1;
1993  }
1994 
1995  char *dest = d->writeBuffer.reserve(len);
1996  memcpy(dest, data, len);
1997  if (d->stdinChannel.notifier)
1998  d->stdinChannel.notifier->setEnabled(true);
1999 #if defined QPROCESS_DEBUG
2000  qDebug("QProcess::writeData(%p \"%s\", %lld) == %lld (written to buffer)",
2001  data, qt_prettyDebug(data, len, 16).constData(), len, len);
2002 #endif
2003  return len;
2004 }
2005 
2014 {
2015  ProcessChannel tmp = readChannel();
2017  QByteArray data = readAll();
2018  setReadChannel(tmp);
2019  return data;
2020 }
2021 
2030 {
2031  ProcessChannel tmp = readChannel();
2033  QByteArray data = readAll();
2034  setReadChannel(tmp);
2035  return data;
2036 }
2037 
2060 void QProcess::start(const QString &program, const QStringList &arguments, OpenMode mode)
2061 {
2062  Q_D(QProcess);
2063  if (d->processState != NotRunning) {
2064  qWarning("QProcess::start: Process is already running");
2065  return;
2066  }
2067 
2068 #if defined QPROCESS_DEBUG
2069  qDebug() << "QProcess::start(" << program << ',' << arguments << ',' << mode << ')';
2070 #endif
2071 
2072  d->outputReadBuffer.clear();
2073  d->errorReadBuffer.clear();
2074 
2075  if (d->stdinChannel.type != QProcessPrivate::Channel::Normal)
2076  mode &= ~WriteOnly; // not open for writing
2077  if (d->stdoutChannel.type != QProcessPrivate::Channel::Normal &&
2078  (d->stderrChannel.type != QProcessPrivate::Channel::Normal ||
2079  d->processChannelMode == MergedChannels))
2080  mode &= ~ReadOnly; // not open for reading
2081  if (mode == 0)
2082  mode = Unbuffered;
2083  QIODevice::open(mode);
2084 
2085  d->stdinChannel.closed = false;
2086  d->stdoutChannel.closed = false;
2087  d->stderrChannel.closed = false;
2088 
2089  d->program = program;
2090  d->arguments = arguments;
2091 
2092  d->exitCode = 0;
2093  d->exitStatus = NormalExit;
2094  d->processError = QProcess::UnknownError;
2095  d->errorString.clear();
2096  d->startProcess();
2097 }
2098 
2099 
2101 {
2102  QStringList args;
2103  QString tmp;
2104  int quoteCount = 0;
2105  bool inQuote = false;
2106 
2107  // handle quoting. tokens can be surrounded by double quotes
2108  // "hello world". three consecutive double quotes represent
2109  // the quote character itself.
2110  for (int i = 0; i < program.size(); ++i) {
2111  if (program.at(i) == QLatin1Char('"')) {
2112  ++quoteCount;
2113  if (quoteCount == 3) {
2114  // third consecutive quote
2115  quoteCount = 0;
2116  tmp += program.at(i);
2117  }
2118  continue;
2119  }
2120  if (quoteCount) {
2121  if (quoteCount == 1)
2122  inQuote = !inQuote;
2123  quoteCount = 0;
2124  }
2125  if (!inQuote && program.at(i).isSpace()) {
2126  if (!tmp.isEmpty()) {
2127  args += tmp;
2128  tmp.clear();
2129  }
2130  } else {
2131  tmp += program.at(i);
2132  }
2133  }
2134  if (!tmp.isEmpty())
2135  args += tmp;
2136 
2137  return args;
2138 }
2139 
2170 void QProcess::start(const QString &program, OpenMode mode)
2171 {
2172  QStringList args = parseCombinedArgString(program);
2173  if (args.isEmpty()) {
2174  Q_D(QProcess);
2175  d->processError = QProcess::FailedToStart;
2176  setErrorString(tr("No program defined"));
2177  emit error(d->processError);
2178  return;
2179  }
2180 
2181  QString prog = args.first();
2182  args.removeFirst();
2183 
2184  start(prog, args, mode);
2185 }
2186 
2211 {
2212  Q_D(QProcess);
2213  d->terminateProcess();
2214 }
2215 
2232 {
2233  Q_D(QProcess);
2234  d->killProcess();
2235 }
2236 
2241 {
2242  Q_D(const QProcess);
2243  return d->exitCode;
2244 }
2245 
2259 {
2260  Q_D(const QProcess);
2261  return d->exitStatus;
2262 }
2263 
2279 int QProcess::execute(const QString &program, const QStringList &arguments)
2280 {
2281  QProcess process;
2283  process.start(program, arguments);
2284  if (!process.waitForFinished(-1))
2285  return -2;
2286  return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1;
2287 }
2288 
2299 int QProcess::execute(const QString &program)
2300 {
2301  QProcess process;
2303  process.start(program);
2304  if (!process.waitForFinished(-1))
2305  return -2;
2306  return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1;
2307 }
2308 
2332 bool QProcess::startDetached(const QString &program,
2333  const QStringList &arguments,
2334  const QString &workingDirectory,
2335  qint64 *pid)
2336 {
2337  return QProcessPrivate::startDetached(program,
2338  arguments,
2339  workingDirectory,
2340  pid);
2341 }
2342 
2358 bool QProcess::startDetached(const QString &program,
2359  const QStringList &arguments)
2360 {
2361  return QProcessPrivate::startDetached(program, arguments);
2362 }
2363 
2377 bool QProcess::startDetached(const QString &program)
2378 {
2379  QStringList args = parseCombinedArgString(program);
2380  if (args.isEmpty())
2381  return false;
2382 
2383  QString prog = args.first();
2384  args.removeFirst();
2385 
2386  return QProcessPrivate::startDetached(prog, args);
2387 }
2388 
2390 #if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
2391 # include <crt_externs.h>
2392 # define environ (*_NSGetEnviron())
2393 #elif defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) || (defined(Q_OS_MAC) && defined(Q_OS_IOS))
2394  static char *qt_empty_environ[] = { 0 };
2395 #define environ qt_empty_environ
2396 #elif !defined(Q_OS_WIN)
2397  extern char **environ;
2398 #endif
2400 
2424 {
2425  QStringList tmp;
2426  char *entry = 0;
2427  int count = 0;
2428  while ((entry = environ[count++]))
2429  tmp << QString::fromLocal8Bit(entry);
2430  return tmp;
2431 }
2432 
2467 
2468 #include "moc_qprocess.cpp"
2469 
2470 #endif // QT_NO_PROCESS
2471 
The QProcessEnvironment class holds the environment variables that can be passed to a program...
Definition: qprocess.h:68
bool _q_canReadStandardOutput()
Definition: qprocess.cpp:937
double d
Definition: qnumeric_p.h:62
void remove(const QString &name)
Removes the environment variable identified by name from this QProcessEnvironment object...
Definition: qprocess.cpp:355
static bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid=0)
Starts the program program with the arguments arguments in a new process, and detaches from it...
Definition: qprocess.cpp:2332
int exitCode() const
Returns the exit code of the last process that finished.
Definition: qprocess.cpp:2240
QString value(const QString &name, const QString &defaultValue=QString()) const
Searches this QProcessEnvironment object for a variable identified by name and returns its value...
Definition: qprocess.cpp:374
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
ProcessChannelMode readChannelMode() const
Returns the read channel mode of the QProcess.
Definition: qprocess.cpp:1241
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
void setProcessState(ProcessState state)
Sets the current state of the QProcess to the state specified.
Definition: qprocess.cpp:1886
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
ProcessError
This enum describes the different types of errors that are reported by QProcess.
Definition: qprocess.h:106
virtual ~QProcess()
Destructs the QProcess object, i.e., killing the process.
Definition: qprocess.cpp:1216
void clear()
Removes all items from the hash.
Definition: qhash.h:574
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
const char * readPointer() const
Definition: qringbuffer_p.h:73
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
Definition: qiodevice.cpp:590
ProcessChannel
This enum describes the process channels used by the running process.
Definition: qprocess.h:119
void closeReadChannel(ProcessChannel channel)
Closes the read channel channel.
Definition: qprocess.cpp:1343
void pipeFrom(QProcessPrivate *other)
Definition: qprocess_p.h:277
QProcessEnvironment & operator=(const QProcessEnvironment &other)
Copies the contents of the other QProcessEnvironment object into this one.
Definition: qprocess.cpp:240
#define it(className, varName)
~QProcessEnvironment()
Frees the resources associated with this QProcessEnvironment object.
Definition: qprocess.cpp:224
QStringList keys() const
Returns a list containing all the variable names in this QProcessEnvironment object.
Definition: qprocess.cpp:417
void pipeTo(QProcessPrivate *other)
Definition: qprocess_p.h:270
void clear()
Removes all key=value pairs from this QProcessEnvironment object, making it empty.
Definition: qprocess.cpp:295
void detach()
If the shared data object&#39;s reference count is greater than 1, this function creates a deep copy of t...
Definition: qshareddata.h:75
void aboutToClose()
This signal is emitted when the device is about to close.
int nextDataBlockSize() const
Definition: qringbuffer_p.h:69
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QProcess::ProcessState state() const
Returns the current state of the process.
Definition: qprocess.cpp:1687
Value prepareValue(const QString &value) const
Definition: qprocess_p.h:154
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
virtual ~QProcessPrivate()
Definition: qprocess.cpp:858
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
Channel stdinChannel
Definition: qprocess_p.h:317
ProcessState
This enum describes the different states of QProcess.
Definition: qprocess.h:114
static bool startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory=QString(), qint64 *pid=0)
QString nameToString(const Key &name) const
Definition: qprocess_p.h:153
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
static QStringList systemEnvironment()
Returns the environment of the calling process as a list of key=value pairs.
Definition: qprocess.cpp:2423
QProcess(QObject *parent=0)
Constructs a QProcess object with the given parent.
Definition: qprocess.cpp:1202
qint64 readData(char *data, qint64 maxlen)
Reimplemented Function
Definition: qprocess.cpp:1917
void setEnvironment(const QStringList &environment)
Sets the environment that QProcess will use when starting a process to the environment specified whic...
Definition: qprocess.cpp:1711
QSharedDataPointer< QProcessEnvironmentPrivate > d
Definition: qprocess.h:99
Key prepareName(const QString &name) const
Definition: qprocess_p.h:152
bool isEmpty() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool atEnd() const
Returns true if the process is not running, and no more data is available for reading; otherwise retu...
Definition: qprocess.cpp:1628
void closeWriteChannel()
Schedules the write channel of QProcess to be closed.
Definition: qprocess.cpp:1371
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
void setWorkingDirectory(const QString &dir)
Sets the working directory to dir.
Definition: qprocess.cpp:1571
Q_PID pid() const
Returns the native process identifier for the running process, if available.
Definition: qprocess.cpp:1581
QString valueToString(const Value &value) const
Definition: qprocess_p.h:155
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
qint64 bytesToWrite() const
Reimplemented Function
Definition: qprocess.cpp:1661
#define INVALID_Q_PIPE
Definition: qprocess_p.h:69
#define Q_D(Class)
Definition: qglobal.h:2482
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
Definition: qiodevice.cpp:711
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
bool isEmpty() const
Returns true if this QProcessEnvironment object is empty: that is there are no key=value pairs set...
Definition: qprocess.cpp:283
virtual void setupChildProcess()
This function is called in the child process context just before the program is executed on Unix or M...
Definition: qprocess.cpp:1911
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
#define Q_Q(Class)
Definition: qglobal.h:2483
static QProcessEnvironment fromList(const QStringList &list)
Definition: qprocess.cpp:167
QProcessEnvironment processEnvironment() const
Returns the environment that QProcess will use when starting a process, or an empty object if no envi...
Definition: qprocess.cpp:1775
void setNativeArguments(const QString &arguments)
Sets additional native command line arguments for the program.
Definition: qprocess.cpp:1534
bool _q_canWrite()
Definition: qprocess.cpp:1036
Q_CORE_EXPORT void qDebug(const char *,...)
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
bool operator==(const QProcessEnvironment &other) const
Returns true if this and the other QProcessEnvironment objects are equal.
Definition: qprocess.cpp:266
void terminate()
Attempts to terminate the process.
Definition: qprocess.cpp:2210
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool waitForFinished(int msecs=30000)
Blocks until the process has finished and the finished() signal has been emitted, or until msecs mill...
Definition: qprocess.cpp:1863
QProcess::ExitStatus exitStatus() const
Returns the exit status of the last process that finished.
Definition: qprocess.cpp:2258
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
void truncate(int pos)
Truncates the string at the given position index.
Definition: qstring.cpp:4603
void setStandardInputFile(const QString &fileName)
Redirects the process&#39; standard input to the file indicated by fileName.
Definition: qprocess.cpp:1399
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
ProcessChannelMode
This enum describes the process channel modes of QProcess.
Definition: qprocess.h:123
static int execute(const QString &program, const QStringList &arguments)
Starts the program program with the arguments arguments in a new process, waits for it to finish...
Definition: qprocess.cpp:2279
void closeWriteChannel()
Definition: qprocess.cpp:1178
bool contains(const QString &name) const
Returns true if the environment variable of name name is found in this QProcessEnvironment object...
Definition: qprocess.cpp:313
const char * name
Channel stdoutChannel
Definition: qprocess_p.h:318
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
bool _q_startupNotification()
Definition: qprocess.cpp:1149
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:859
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
QProcess::ProcessError error() const
Returns the type of error that occurred last.
Definition: qprocess.cpp:1676
void setStandardOutputProcess(QProcess *destination)
Pipes the standard output stream of this process to the destination process&#39; standard input...
Definition: qprocess.cpp:1484
void setProcessEnvironment(const QProcessEnvironment &environment)
Sets the environment that QProcess will use when starting a process to the environment object...
Definition: qprocess.cpp:1754
void setReadChannelMode(ProcessChannelMode mode)
Use setProcessChannelMode(mode) instead.
Definition: qprocess.cpp:1256
const T * ptr(const T &t)
__int64 qint64
Definition: qglobal.h:942
QStringList toList() const
Definition: qprocess.cpp:150
void started()
This signal is emitted by QProcess when the process has started, and state() returns Running ...
bool canReadLine() const
This function operates on the current read channel.
Definition: qprocess.cpp:1596
void insert(const QProcessEnvironmentPrivate &other)
Definition: qprocess.cpp:196
void setReadChannel(ProcessChannel channel)
Sets the current read channel of the QProcess to the given channel.
Definition: qprocess.cpp:1317
void close()
Closes all communication with the process and kills it.
Definition: qprocess.cpp:1610
QByteArray readAllStandardError()
Regardless of the current read channel, this function returns all data available from the standard er...
Definition: qprocess.cpp:2029
QStringList toStringList() const
Converts this QProcessEnvironment object into a list of strings, one for each environment variable th...
Definition: qprocess.cpp:400
ProcessChannel readChannel() const
Returns the current read channel of the QProcess.
Definition: qprocess.cpp:1303
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
QString workingDirectory() const
If QProcess has been assigned a working directory, this function returns the working directory that t...
Definition: qprocess.cpp:1551
qint64 Q_PID
Definition: qprocess.h:58
ExitStatus
This enum describes the different exit statuses of QProcess.
Definition: qprocess.h:128
void setStandardOutputFile(const QString &fileName, OpenMode mode=Truncate)
Redirects the process&#39; standard output to the file fileName.
Definition: qprocess.cpp:1430
QString & append(QChar c)
Definition: qstring.cpp:1777
void free(int bytes)
void qDeleteInEventHandler(QObject *o)
Definition: qobject.cpp:4348
int size() const
Returns the number of items in the hash.
Definition: qhash.h:295
void setStandardErrorFile(const QString &fileName, OpenMode mode=Truncate)
Redirects the process&#39; standard error to the file fileName.
Definition: qprocess.cpp:1460
QStringList keys() const
Definition: qprocess.cpp:185
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
void setErrorString(const QString &errorString)
Sets the human readable description of the last device error that occurred to str.
Definition: qiodevice.cpp:1660
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
QString nativeArguments() const
Returns the additional native command line arguments for the program.
Definition: qprocess.cpp:1507
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
bool canReadLine() const
bool waitForReadyRead(int msecs=30000)
Reimplemented Function
Definition: qprocess.cpp:1811
static void cleanup()
Definition: qpicture.cpp:1508
if(void) toggleToolbarShown
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
void kill()
Kills the current process, causing it to exit immediately.
Definition: qprocess.cpp:2231
int qsnprintf(char *str, size_t n, const char *fmt,...)
A portable snprintf() function, calls qvsnprintf.
Definition: qvsnprintf.cpp:128
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
QProcessEnvironment()
Creates a new QProcessEnvironment object.
Definition: qprocess.cpp:216
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
void start(const QString &program, const QStringList &arguments, OpenMode mode=ReadWrite)
Starts the given program in a new process, if none is already running, passing the command line argum...
Definition: qprocess.cpp:2060
bool _q_canReadStandardError()
Definition: qprocess.cpp:992
void setProcessChannelMode(ProcessChannelMode mode)
Sets the channel mode of the QProcess standard output and standard error channels to the mode specifi...
Definition: qprocess.cpp:1292
void stateChanged(QProcess::ProcessState state)
This signal is emitted whenever the state of QProcess changes.
bool _q_processDied()
Definition: qprocess.cpp:1080
qint64 bytesAvailable() const
Reimplemented Function
Definition: qprocess.cpp:1646
QByteArray readAllStandardOutput()
Regardless of the current read channel, this function returns all data available from the standard ou...
Definition: qprocess.cpp:2013
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
Definition: qiodevice.cpp:1330
bool waitForBytesWritten(int msecs=30000)
Reimplemented Function
Definition: qprocess.cpp:1826
bool waitForStarted(int msecs=30000)
Blocks until the process has started and the started() signal has been emitted, or until msecs millis...
Definition: qprocess.cpp:1800
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
QStringList environment() const
Returns the environment that QProcess will use when starting a process, or an empty QStringList if no...
Definition: qprocess.cpp:1731
ProcessChannelMode processChannelMode() const
Returns the channel mode of the QProcess standard output and standard error channels.
Definition: qprocess.cpp:1272
static const KeyPair *const end
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
#define environ
Definition: qprocess.cpp:2392
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QString fileName(const QString &fileUrl)
void start()
Starts this timer.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static QStringList parseCombinedArgString(const QString &program)
Definition: qprocess.cpp:2100
qint64 writeData(const char *data, qint64 len)
Reimplemented Function
Definition: qprocess.cpp:1963
The QProcess class is used to start external programs and to communicate with them.
Definition: qprocess.h:102
void insert(const QString &name, const QString &value)
Inserts the environment variable of name name and contents value into this QProcessEnvironment object...
Definition: qprocess.cpp:337
void reserve(int size)
Reserve space for alloc elements.
Definition: qlist.h:496
int size() const
bool isSequential() const
Reimplemented Function
Definition: qprocess.cpp:1639
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272