I’m having a strange issue with a connection not working properly as a queed connection. The idea is that we need to kill an QProcess, start another process, then allow the program to run the exit function. The app exit processes only when used as direct but this causes an issue with calling the exit prematurely.
// notify windows ce we started
int main()
{
test s;
return a.exec();
}
test.cpp
#include "StdAfx.h"
test::test(QObject *parent) :
QObject(parent)
{
firstApp = new QProcess(this);
ahurarun = new QProcess(this);
// connect both exits to appExit
connect(firstApp, SIGNAL(finished(int,QProcess::ExitStatus)),
this, SLOT(appExit(int,QProcess::ExitStatus)),
Qt::QueuedConnection);
firstApp->start("some app");
}
void test::startSecondApp()
{
if(QProcess::Running == firstApp->state())
{
// politely ask app to close
firstApp->terminate();
// then kill it if it doesn't
QTimer::singleShot(10000, firstApp, SLOT(kill()));
firstApp->waitForFinished(15000);
}
secondApp->start("some app");
if(!secondApp->waitForStarted(30000))
{
}
}
void test::appExit(int exitCode, QProcess::ExitStatus exitStatus)
{
if(QObject::sender() == firstApp)
{
qDebug() << "firstApp exited early with code=" << QString::number(exitCode);
if(QProcess::Running != secondApp->state())
{
// display some error for the app if it wasn't us
}
}
}
↧