I'm new to QT so I'm sure I'm either misunderstanding something or just doing something wrong.
The problem is that when I run the code below, it opens up the application and also immediately
calls the finished() function even though the application is still running. I wouldn't expect it to
emit the finished signal until after the application has exited?
What am I missing?
Here is my test code.
*****************************************
mainwindow.h
==========
private slots:
void procEditFinished
(int exitCode,
QProcess::ExitStatus exitStatus
);
private:
private slots:
void procEditFinished(int exitCode, QProcess::ExitStatus exitStatus);
private:
QProcess *procEdit;
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
============
void MainWindow::on_btnEdit_clicked()
{
arg << "file.txt";
connect(procEdit,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(procEditFinished
(int,
QProcess::ExitStatus)));
procEdit->start(app, arg);
}
void MainWindow
::procEditFinished(int exitCode,
QProcess::ExitStatus exitStatus
) {
qDebug("exitCode= %d, exitStatus= %d", exitCode, exitStatus);
procEdit->deleteLater();
}
void MainWindow::on_btnEdit_clicked()
{
QString app = "/usr/bin/gedit";
QStringList arg;
arg << "file.txt";
procEdit = new QProcess(this);
connect(procEdit, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(procEditFinished(int, QProcess::ExitStatus)));
procEdit->start(app, arg);
}
void MainWindow::procEditFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
qDebug("exitCode= %d, exitStatus= %d", exitCode, exitStatus);
procEdit->deleteLater();
}
To copy to clipboard, switch view to plain text mode
Bookmarks