Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Restart app does not work
Forum Updated to NodeBB v4.3 + New Features

Restart app does not work

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.1k Views 1 Watching
  • 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.
  • guidupasG Offline
    guidupasG Offline
    guidupas
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • guidupasG Offline
        guidupasG Offline
        guidupas
        wrote on last edited by
        #3

        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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • guidupasG Offline
            guidupasG Offline
            guidupas
            wrote on last edited by
            #5

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              0
              • guidupasG Offline
                guidupasG Offline
                guidupas
                wrote on last edited by
                #7

                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
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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
                  0
                  • guidupasG Offline
                    guidupasG Offline
                    guidupas
                    wrote on last edited by
                    #9

                    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
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved