Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Restart app does not work

    General and Desktop
    2
    10
    2665
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • guidupas
      guidupas last edited by

      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.

      Att.
      Guilherme Cortada Dupas

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • guidupas
          guidupas last edited by

          Well, I tried this and still not working

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

          Not even when I run in Qt

          Att.
          Guilherme Cortada Dupas

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Did you check what value both calls return ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • guidupas
              guidupas last edited by

              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

              Att.
              Guilherme Cortada Dupas

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

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

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • guidupas
                  guidupas last edited by

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

                  Thanks a lot.

                  Att.
                  Guilherme Cortada Dupas

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    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

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply Reply Quote 0
                    • guidupas
                      guidupas last edited by

                      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

                      Att.
                      Guilherme Cortada Dupas

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

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

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post