27 #include <QMessageBox> 29 QgsRunProcess::QgsRunProcess(
const QString &action,
bool capture )
38 mProcess =
new QProcess;
42 connect( mProcess, static_cast <
void ( QProcess::* )( QProcess::ProcessError ) >( &QProcess::error ),
this, &
QgsRunProcess::processError );
48 connect( mProcess, static_cast <
void ( QProcess::* )(
int, QProcess::ExitStatus ) >( &QProcess::finished ),
this, &
QgsRunProcess::processExit );
58 QObject *mOutputObj =
dynamic_cast<QObject *
>( mOutput );
65 mProcess->start( action );
69 if ( ! mProcess->startDetached( action ) )
71 QMessageBox::critical(
nullptr, tr(
"Action" ),
72 tr(
"Unable to run command\n%1" ).arg( action ),
73 QMessageBox::Ok, Qt::NoButton );
81 QgsRunProcess::~QgsRunProcess()
86 void QgsRunProcess::die()
94 QByteArray bytes( mProcess->readAllStandardOutput() );
95 QTextCodec *codec = QTextCodec::codecForLocale();
96 QString line( codec->toUnicode( bytes ) );
104 QByteArray bytes( mProcess->readAllStandardOutput() );
105 QTextCodec *codec = QTextCodec::codecForLocale();
106 QString line( codec->toUnicode( bytes ) );
109 mOutput->
appendMessage(
"<font color=red>" + line +
"</font>" );
143 disconnect( mProcess, static_cast <
void ( QProcess::* )( QProcess::ProcessError ) >( &QProcess::error ),
this, &
QgsRunProcess::processError );
146 disconnect( mProcess, static_cast <
void ( QProcess::* )(
int, QProcess::ExitStatus ) >( &QProcess::finished ),
this, &
QgsRunProcess::processExit );
153 if ( err == QProcess::FailedToStart )
162 QgsDebugMsg(
"Got error: " + QString(
"%d" ).arg( err ) );
virtual void setTitle(const QString &title)=0
set title for the messages
static QgsMessageOutput * createMessageOutput()
function that returns new class derived from QgsMessageOutput (don't forget to delete it then if show...
virtual void appendMessage(const QString &message)=0
message to be appended to the current text
virtual void setMessage(const QString &message, MessageType msgType)=0
set message, it won't be displayed until
void processError(QProcess::ProcessError)
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
void processExit(int, QProcess::ExitStatus)
Interface for showing messages from QGIS in GUI independent way.