Restart app does not work
-
Hello!
I am trying to restart my app using the code:
@
QStringList args = QApplication::arguments();
args.removeFirst();
QProcess::startDetached(QApplication::applicationFilePath(), args);
QCoreApplication::quit();
@or
@
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
qApp->quit();
@It works fine when I run it in Qt, but when I build it, generate the .pkg and install it does not restart and when I reopen the app it gives a message that the app was finished during windows reopen.
I am using OSX 10.9
Thanks very much.
-
Hi,
You should rather use the QCoreApplication::applicationFilePath method to retrieve the executable's location. qApp->arguments()[0] might not contain what you think, especially on 10.9
Hope it helps
-
Did you check what value both calls return ?
-
Well, when I run
@
qDebug() << QApplication::applicationFilePath();
@It returns:
@
"/Users/guilhermedupas/Dropbox/Guilherme - Particular/QT/Projetos/build-SwotGut-Desktop_Qt_5_3_0_clang_64bit-Release/SwotGut.app/Contents/MacOS/SwotGut"
@This is the correct location of the executable
-
For the sake of testing, try starting it normally with QProcess and check what error you might get
-
Just follow the example from "here":http://qt-project.org/doc/qt-5/qprocess.html#synchronous-process-api and check what you have in both output channels
-
SGaist, I did the process like the example:
@
QObject *parent;
QString program = "/Users/guilhermedupas/Dropbox/Guilherme - Particular/QT/Projetos/build-SwotGut-Desktop_Qt_5_3_0_clang_64bit-Release/SwotGut.app/Contents/MacOS/SwotGut";QStringList arguments;
arguments << "-style" << "fusion";QProcess *myProcess = new QProcess(parent); myProcess->start(program, arguments); if (!myProcess->waitForStarted()) qDebug() << "false"; if (!myProcess->waitForFinished()) qDebug() << "false"; QString result = myProcess->readAll(); qDebug() << result;
@
My program runs, but when I click in the action to restart that uses this code:
@
QProcess::startDetached(QCoreApplication::applicationFilePath());
QCoreApplication::quit();
@Console returns this: ""
And I need to use control c to exit and in Qt output appears crashed -
IIRC, since you didn't merge both channels, you need to call read readAllStandardError and readAllStandardOutput to check what happened