PDA

View Full Version : Qt start new application and quit



TheQuake
3rd January 2015, 20:39
Hello! I posted my issue on stackoverflow: http://stackoverflow.com/questions/27736976/qt-start-new-application-and-quit?noredirect=1#comment43893521_27736976
I have no idea how to run other application in background from main application. Every time main application is quitting, applications started by it are closed too.

I have tried to use Q_DESTRUCTOR_FUNCTION to run process after main() is processing, without result. I also tried a lot of function:


void closeApp()
{
QProcess test;
if(test.startDetached("cmd.exe &"))
qDebug() << "Running";
QProcess::execute("cmd.exe");
system("start cmd.exe &");
system("cmd.exe &");
execl("start cmd.exe", "ls", "-r", "-t", "-l", (char *) 0);
system("cmd.exe");
FILE* pd = popen("cmd.exe &", "r");
}

Q_DESTRUCTOR_FUNCTION(closeApp)

Is it possible to launch and keep process by running from main application?
edit: ok, the problem was debugger .. outside it all works great with simple QProcess::startDetached("xxx");

ChrisW67
3rd January 2015, 23:55
Yes, it is possible using QProcess::startDetached() and passing it a path to a valid executable and optionally arguments and a working directory.
This code works just fine:


#include <QCoreApplication>
#include <QProcess>
#include <QDebug>

int main(int argc, char **argv) {
QCoreApplication app(argc, argv);

bool ok = QProcess::startDetached("notepad.exe");
qDebug() << ok;
return 0;
}
with a Windows notepad left running after program exit.

TheQuake
4th January 2015, 00:41
Yeah you're right, but this works only outside debugger. If you try to debug it, it won't work.

ChrisW67
4th January 2015, 08:22
It works fine here when run in the Gnu Debugger (Qt 4.8.4 MingW)