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.


  • Lifetime Qt Champion

    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



  • Well, I tried this and still not working

    @
    QProcess::startDetached(QCoreApplication::applicationFilePath());
    qApp->quit();
    @

    Not even when I run in Qt


  • Lifetime Qt Champion

    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


  • Lifetime Qt Champion

    For the sake of testing, try starting it normally with QProcess and check what error you might get



  • Can you help me how to do that? How can I see the returned error?

    Thanks a lot.


  • Lifetime Qt Champion

    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


  • Lifetime Qt Champion

    IIRC, since you didn't merge both channels, you need to call read readAllStandardError and readAllStandardOutput to check what happened


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.