You can't do it well in a single method because you'll freeze the UI.
waitForFinished() is a blocking call and will make your app unresponsive.
Instead, you should use finished() signal from QProcess and connect it to a slot which will terminate the process.
As to the other issue, it should be obvious why you get the message - it's because you never exit the process and try to run it again (unless you do it in other place which you didn't show).
void MainWindow::MainWindow()
{
connect( process3, SIGNAL( finished() ), this, SLOT( process3FinishedSlot() ) );
}
void MainWindow::on_pushbuttonclicked()
{
process3->setWorkingDirectory ("/hdrd/iimd/");
process3->start ("gnuplot");
process3->waitForStarted(); // blocking call, consider using started() signal if it takes long to start the process
process3->write( "set pm3d\n" );
process3->write( "splot \"plot.dat\" u 1:2:3 with line &\n" );
}
void MainWindow::process3FinishedSlot( void )
{
process3->close();
}
void MainWindow::MainWindow()
{
connect( process3, SIGNAL( finished() ), this, SLOT( process3FinishedSlot() ) );
}
void MainWindow::on_pushbuttonclicked()
{
process3->setWorkingDirectory ("/hdrd/iimd/");
process3->start ("gnuplot");
process3->waitForStarted(); // blocking call, consider using started() signal if it takes long to start the process
process3->write( "set pm3d\n" );
process3->write( "splot \"plot.dat\" u 1:2:3 with line &\n" );
}
void MainWindow::process3FinishedSlot( void )
{
process3->close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks