A QProcess subclass for code-blocking process execution. More...
#include <klfblockprocess.h>
Public Slots | |
bool | startProcess (QStringList cmd, QByteArray stdindata, QStringList env=QStringList()) |
bool | startProcess (QStringList cmd, QStringList env=QStringList()) |
QString | readStderrString () |
QString | readStdoutString () |
Public Member Functions | |
KLFBlockProcess (QObject *parent=0) | |
~KLFBlockProcess () | |
void | setProcessAppEvents (bool processAppEvents) |
QByteArray | getAllStderr () |
QByteArray | getAllStdout () |
bool | processNormalExit () const |
int | processExitStatus () const |
virtual QString | getInterpreterPath (const QString &ext) |
The interpter path to use for the given extension. More... | |
![]() | |
QProcess (QObject *parent) | |
void | start (const QString &program, const QStringList &arguments, OpenMode mode) |
void | start (const QString &command, OpenMode mode) |
void | start (OpenMode mode) |
virtual bool | open (OpenMode mode) |
QString | program () const |
void | setProgram (const QString &program) |
QStringList | arguments () const |
void | setArguments (const QStringList &arguments) |
ProcessChannelMode | readChannelMode () const |
void | setReadChannelMode (ProcessChannelMode mode) |
ProcessChannelMode | processChannelMode () const |
void | setProcessChannelMode (ProcessChannelMode mode) |
InputChannelMode | inputChannelMode () const |
void | setInputChannelMode (InputChannelMode mode) |
ProcessChannel | readChannel () const |
void | setReadChannel (ProcessChannel channel) |
void | closeReadChannel (ProcessChannel channel) |
void | closeWriteChannel () |
void | setStandardInputFile (const QString &fileName) |
void | setStandardOutputFile (const QString &fileName, OpenMode mode) |
void | setStandardErrorFile (const QString &fileName, OpenMode mode) |
void | setStandardOutputProcess (QProcess *destination) |
QString | nativeArguments () const |
void | setNativeArguments (const QString &arguments) |
CreateProcessArgumentModifier | createProcessArgumentsModifier () const |
void | setCreateProcessArgumentsModifier (CreateProcessArgumentModifier modifier) |
QString | workingDirectory () const |
void | setWorkingDirectory (const QString &dir) |
void | setEnvironment (const QStringList &environment) |
QStringList | environment () const |
void | setProcessEnvironment (const QProcessEnvironment &environment) |
QProcessEnvironment | processEnvironment () const |
QProcess::ProcessError | error () const |
QProcess::ProcessState | state () const |
Q_PID | pid () const |
qint64 | processId () const |
bool | waitForStarted (int msecs) |
virtual bool | waitForReadyRead (int msecs) |
virtual bool | waitForBytesWritten (int msecs) |
bool | waitForFinished (int msecs) |
QByteArray | readAllStandardOutput () |
QByteArray | readAllStandardError () |
int | exitCode () const |
QProcess::ExitStatus | exitStatus () const |
virtual qint64 | bytesAvailable () const |
virtual qint64 | bytesToWrite () const |
virtual bool | isSequential () const |
virtual bool | canReadLine () const |
virtual void | close () |
virtual bool | atEnd () const |
void | terminate () |
void | kill () |
void | started () |
void | finished (int exitCode) |
void | finished (int exitCode, QProcess::ExitStatus exitStatus) |
void | error (QProcess::ProcessError error) |
void | errorOccurred (QProcess::ProcessError error) |
void | stateChanged (QProcess::ProcessState newState) |
void | readyReadStandardOutput () |
void | readyReadStandardError () |
![]() | |
QIODevice (QObject *parent) | |
OpenMode | openMode () const |
void | setTextModeEnabled (bool enabled) |
bool | isTextModeEnabled () const |
bool | isOpen () const |
bool | isReadable () const |
bool | isWritable () const |
int | readChannelCount () const |
int | writeChannelCount () const |
int | currentReadChannel () const |
void | setCurrentReadChannel (int channel) |
int | currentWriteChannel () const |
void | setCurrentWriteChannel (int channel) |
virtual qint64 | pos () const |
virtual qint64 | size () const |
virtual bool | seek (qint64 pos) |
virtual bool | reset () |
qint64 | read (char *data, qint64 maxSize) |
QByteArray | read (qint64 maxSize) |
QByteArray | readAll () |
qint64 | readLine (char *data, qint64 maxSize) |
QByteArray | readLine (qint64 maxSize) |
void | startTransaction () |
void | commitTransaction () |
void | rollbackTransaction () |
bool | isTransactionStarted () const |
qint64 | write (const char *data, qint64 maxSize) |
qint64 | write (const char *data) |
qint64 | write (const QByteArray &byteArray) |
qint64 | peek (char *data, qint64 maxSize) |
QByteArray | peek (qint64 maxSize) |
void | ungetChar (char c) |
bool | putChar (char c) |
bool | getChar (char *c) |
QString | errorString () const |
void | readyRead () |
void | channelReadyRead (int channel) |
void | bytesWritten (qint64 bytes) |
void | channelBytesWritten (int channel, qint64 bytes) |
void | aboutToClose () |
void | readChannelFinished () |
![]() | |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
virtual const QMetaObject * | metaObject () const |
QString | objectName () const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const |
bool | isWindowType () const |
bool | signalsBlocked () const |
bool | blockSignals (bool block) |
QThread * | thread () const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const |
const QObjectList & | children () const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const |
bool | disconnect (const QObject *receiver, const char *method) const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const |
QList< QByteArray > | dynamicPropertyNames () const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const |
bool | inherits (const char *className) const |
void | deleteLater () |
Static Public Member Functions | |
static QString | detectInterpreterPath (const QString &interp, const QStringList &addpaths=QStringList()) |
![]() | |
int | execute (const QString &program, const QStringList &arguments) |
int | execute (const QString &command) |
bool | startDetached (const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid) |
bool | startDetached (const QString &command) |
QStringList | systemEnvironment () |
QString | nullDevice () |
![]() | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
Additional Inherited Members | |
![]() | |
typedef | CreateProcessArgumentModifier |
![]() | |
typedef | OpenMode |
![]() | |
void | setProcessState (ProcessState state) |
virtual void | setupChildProcess () |
virtual qint64 | readData (char *data, qint64 maxlen) |
virtual qint64 | writeData (const char *data, qint64 len) |
![]() | |
virtual qint64 | readLineData (char *data, qint64 maxSize) |
void | setOpenMode (OpenMode openMode) |
void | setErrorString (const QString &str) |
![]() | |
QObject * | sender () const |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
![]() | |
objectName | |
A QProcess subclass for code-blocking process execution.
A Code-blocking (but not GUI-blocking) process executor
Use for example like:
This class provides functionality for passing data to STDIN and getting data from STDOUT and STDERR afterwards.
Definition at line 56 of file klfblockprocess.h.
KLFBlockProcess::KLFBlockProcess | ( | QObject * | parent = 0 | ) |
Normal constructor, like QProcess constructor
Definition at line 97 of file klfblockprocess.cpp.
References QObject::connect(), and QProcess::finished().
KLFBlockProcess::~KLFBlockProcess | ( | ) |
Normal destructor
Definition at line 105 of file klfblockprocess.cpp.
|
inline |
Returns all standard error output as a QByteArray. This function is to standardize the readStderr() and readAllStandardError() functions in QT 3 or QT 4 respectively
Definition at line 72 of file klfblockprocess.h.
References QProcess::readAllStandardError().
Referenced by KLFFilterProcess::do_run().
|
inline |
Returns all standard output as a QByteArray. This function is to standardize the readStdout() and readAllStandardOutput() functions in QT 3 or QT 4 respectively
Definition at line 78 of file klfblockprocess.h.
References QProcess::readAllStandardOutput().
Referenced by KLFFilterProcess::do_run().
The interpter path to use for the given extension.
This function will be queried by startProcess() when we have to execute a script.
Subclasses may reimplement to e.g. query user settings etc. Subclasses may of course also make use of detectInterpreterPath().
The default implementation treats some common script extensions ("py", "rb", "sh") and tries to find the interpreter using detectInterpreterPath().
Definition at line 118 of file klfblockprocess.cpp.
References KLF_DEBUG_BLOCK, KLF_FUNC_NAME, and klfDbg.
Referenced by startProcess().
|
inline |
Same as QProcess::exitCode()
Definition at line 88 of file klfblockprocess.h.
References QProcess::exitCode().
Referenced by KLFFilterProcess::do_run().
|
inline |
Same as QProcess::exitStatus()==NormalExit
Definition at line 83 of file klfblockprocess.h.
References QProcess::exitStatus().
Referenced by KLFFilterProcess::do_run().
|
inlineslot |
Same as getAllStderr(), except result is returned here as QString.
Definition at line 128 of file klfblockprocess.h.
References QString::fromLocal8Bit().
Referenced by KLFFilterProcess::do_run().
|
inlineslot |
Same as getAllStdout(), except result is returned here as QString.
Definition at line 132 of file klfblockprocess.h.
References QString::fromLocal8Bit().
Referenced by KLFFilterProcess::do_run().
|
inline |
specify whether or not to call regularly qApp->processEvents() while executing. This will prevent the GUI to freeze. Enabled is the default. However you can choose to disable this behavior by passing FALSE here.
Definition at line 68 of file klfblockprocess.h.
Referenced by KLFFilterProcess::do_run().
|
slot |
Starts cmd (which is a list of arguments, the first being the program itself) and blocks until process stopped. The QT event loop is updated regularly so that the GUI doesn't freeze.
Read result with QProcess::readStdout() and QProcess::readStderr(), get process exit info with processNormalExit() and processExitStatus().
Definition at line 137 of file klfblockprocess.cpp.
References QList::begin(), QProcess::closeWriteChannel(), QByteArray::constData(), QThread::currentThread(), QProcess::environment(), QList::erase(), QProcess::error(), getInterpreterPath(), KLF_ASSERT_CONDITION, klfDbg, QList::last(), QList::prepend(), QCoreApplication::processEvents(), QProcess::program(), QProcess::setEnvironment(), QList::size(), QByteArray::size(), QProcess::start(), QString::toLocal8Bit(), QProcess::waitForFinished(), QProcess::waitForStarted(), and QIODevice::write().
Referenced by KLFFilterProcess::do_run(), and startProcess().
|
slot |
Convenient function to be used in the case where program doesn't expect stdin data or if you chose to directly close stdin without writing anything to it.
Definition at line 132 of file klfblockprocess.cpp.
References startProcess().