Qt 4.8
Macros | Functions
qprocess_win.cpp File Reference
#include "qprocess.h"
#include "qprocess_p.h"
#include "qwindowspipewriter_p.h"
#include <qdatetime.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <qregexp.h>
#include <qtimer.h>
#include <qthread.h>
#include <qmutex.h>
#include <qwaitcondition.h>
#include <private/qwineventnotifier_p.h>
#include <private/qthread_p.h>
#include <qdebug.h>
#include "private/qfsfileengine_p.h"

Go to the source code of this file.

Macros

#define NOTIFYTIMEOUT   100
 

Functions

static QString qt_create_commandline (const QString &program, const QStringList &arguments)
 
static void qt_create_pipe (Q_PIPE *pipe, bool in)
 
static BOOL QT_WIN_CALLBACK qt_terminateApp (HWND hwnd, LPARAM procId)
 

Macro Definition Documentation

◆ NOTIFYTIMEOUT

#define NOTIFYTIMEOUT   100

Function Documentation

◆ qt_create_commandline()

static QString qt_create_commandline ( const QString program,
const QStringList arguments 
)
static

Definition at line 245 of file qprocess_win.cpp.

Referenced by QProcessPrivate::pipeWriterBytesToWrite().

246 {
247  QString args;
248  if (!program.isEmpty()) {
249  QString programName = program;
250  if (!programName.startsWith(QLatin1Char('\"')) && !programName.endsWith(QLatin1Char('\"')) && programName.contains(QLatin1Char(' ')))
251  programName = QLatin1Char('\"') + programName + QLatin1Char('\"');
252  programName.replace(QLatin1Char('/'), QLatin1Char('\\'));
253 
254  // add the prgram as the first arg ... it works better
255  args = programName + QLatin1Char(' ');
256  }
257 
258  for (int i=0; i<arguments.size(); ++i) {
259  QString tmp = arguments.at(i);
260  // Quotes are escaped and their preceding backslashes are doubled.
261  tmp.replace(QRegExp(QLatin1String("(\\\\*)\"")), QLatin1String("\\1\\1\\\""));
262  if (tmp.isEmpty() || tmp.contains(QLatin1Char(' ')) || tmp.contains(QLatin1Char('\t'))) {
263  // The argument must not end with a \ since this would be interpreted
264  // as escaping the quote -- rather put the \ behind the quote: e.g.
265  // rather use "foo"\ than "foo\"
266  int i = tmp.length();
267  while (i > 0 && tmp.at(i - 1) == QLatin1Char('\\'))
268  --i;
269  tmp.insert(i, QLatin1Char('"'));
270  tmp.prepend(QLatin1Char('"'));
271  }
272  args += QLatin1Char(' ') + tmp;
273  }
274  return args;
275 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString & prepend(QChar c)
Definition: qstring.h:261
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qt_create_pipe()

static void qt_create_pipe ( Q_PIPE pipe,
bool  in 
)
static

Definition at line 69 of file qprocess_win.cpp.

70 {
71  // Open the pipes. Make non-inheritable copies of input write and output
72  // read handles to avoid non-closable handles (this is done by the
73  // DuplicateHandle() call).
74 
75 #if !defined(Q_OS_WINCE)
76  SECURITY_ATTRIBUTES secAtt = { sizeof( SECURITY_ATTRIBUTES ), NULL, TRUE };
77 
78  HANDLE tmpHandle;
79  if (in) { // stdin
80  if (!CreatePipe(&pipe[0], &tmpHandle, &secAtt, 1024 * 1024))
81  return;
82  if (!DuplicateHandle(GetCurrentProcess(), tmpHandle, GetCurrentProcess(),
83  &pipe[1], 0, FALSE, DUPLICATE_SAME_ACCESS))
84  return;
85  } else { // stdout or stderr
86  if (!CreatePipe(&tmpHandle, &pipe[1], &secAtt, 1024 * 1024))
87  return;
88  if (!DuplicateHandle(GetCurrentProcess(), tmpHandle, GetCurrentProcess(),
89  &pipe[0], 0, FALSE, DUPLICATE_SAME_ACCESS))
90  return;
91  }
92 
93  CloseHandle(tmpHandle);
94 #else
95  Q_UNUSED(pipe);
96  Q_UNUSED(in);
97 #endif
98 }
#define FALSE
Synonym for false.
Definition: qglobal.h:1019
void * HANDLE
Definition: qnamespace.h:1671
#define TRUE
Synonym for true.
Definition: qglobal.h:1018
#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

◆ qt_terminateApp()

static BOOL QT_WIN_CALLBACK qt_terminateApp ( HWND  hwnd,
LPARAM  procId 
)
static

Definition at line 557 of file qprocess_win.cpp.

558 {
559  DWORD currentProcId = 0;
560  GetWindowThreadProcessId(hwnd, &currentProcId);
561  if (currentProcId == (DWORD)procId)
562  PostMessage(hwnd, WM_CLOSE, 0, 0);
563 
564  return TRUE;
565 }
#define TRUE
Synonym for true.
Definition: qglobal.h:1018