Qt start new application and quit
Hello! I posted my issue on stackoverflow: http://stackoverflow.com/questions/2...93521_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:
Code:
void closeApp()
{
if(test.startDetached("cmd.exe &"))
qDebug() << "Running";
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");
Re: Qt start new application and quit
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:
Code:
#include <QCoreApplication>
#include <QProcess>
#include <QDebug>
int main(int argc, char **argv) {
bool ok
= QProcess::startDetached("notepad.exe");
qDebug() << ok;
return 0;
}
with a Windows notepad left running after program exit.
Re: Qt start new application and quit
Yeah you're right, but this works only outside debugger. If you try to debug it, it won't work.
Re: Qt start new application and quit
It works fine here when run in the Gnu Debugger (Qt 4.8.4 MingW)