Ещё раз привет всем!
Задача следующая При запуске программы выполнять проверку - Если процесс с данным именем уже запущен, показывать предупреждение, и завершать выполнение программы - Если процес не запущен - продолжать выполнение
Пробовал реализовывать посредством сигналов... В документации к http://doc.qt.nokia.com/latest/qprocess.html написано следующее:
| Цитата | void QProcess::start ( const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite )
Starts the given program in a new process, if none is already running, passing the command line arguments in arguments. The OpenMode is set to mode.
The QProcess object will immediately enter the Starting state. If the process starts successfully, QProcess will emit started(); otherwise, error() will be emitted. If the QProcess object is already running a process, a warning may be printed at the console, and the existing process will continue running.
Note: Processes are started asynchronously, which means the started() and error() signals may be delayed. Call waitForStarted() to make sure the process has started (or has failed to start) and those signals have been emitted.
|
| Код | Process::Process() { connect(&m_process, SIGNAL(started()), this, SLOT(started()) );
connect(&m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError)) ); }
Process::~Process() {
}
void Process::start() { m_process.start("ExeText.exe"); if (!m_process.waitForFinished()) { QMessageBox::warning(0, "Error", "Error"); } else { QMessageBox::information(0, "Success", "Success"); } }
void Process::started() { //QMessageBox::information(0, "Success", "Success"); }
void Process::error(QProcess::ProcessError error) { //QMessageBox::warning(0, "Error", "Error"); }
|
Но это не помогает Ещё написано про состояние процесса...
| Цитата | When the process exits, QProcess reenters the NotRunning state (the initial state), and emits finished().
|
Но я это не пробовал...
Что посоветуете, как можно решить эту проблему? Буду благодарен за любой совет! |