Use QProcess::start(), instead of QProcess::execute().
void MainWindow::on_button_clicked()
{
if (p)
{
p
->setEnvironment
( QProcess::systemEnvironment() );
p
->setProcessChannelMode
( QProcess::MergedChannels );
connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadOut()) );
connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ReadErr()) );
//p->execute("sh /home/user/Desktop/file.sh");
p->start("sh /home/user/Desktop/file.sh");
p->waitForStarted();
}
}
void MainWindow::on_button_clicked()
{
QProcess *p = new QProcess( this );
if (p)
{
p->setEnvironment( QProcess::systemEnvironment() );
p->setProcessChannelMode( QProcess::MergedChannels );
connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadOut()) );
connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ReadErr()) );
//p->execute("sh /home/user/Desktop/file.sh");
p->start("sh /home/user/Desktop/file.sh");
p->waitForStarted();
}
}
To copy to clipboard, switch view to plain text mode
QProcess::execute(), is a static call and will start another new process (which is not p), you actualy need to connect to the signals of the new process created in side execute() function, but you cannot access it.
Bookmarks