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. Close application and relaunch but with an argument..?
Forum Updated to NodeBB v4.3 + New Features

Close application and relaunch but with an argument..?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 3.2k 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.
  • A Offline
    A Offline
    AcerExtensa
    wrote on last edited by
    #2

    How about "QProcess::startDetached?":http://qt-project.org/doc/qt-4.8/qprocess.html#startDetached-2

    @QProcess::startDetached(qApp->applicationFilePath(), QStringList() << "--clock");@

    You can also use small bash script or binary as luncher:
    @
    if(qApp->arguments().count() > 1)
    {
    sleep(2);
    QProcess::startDetached(qApp->applicationDirPath()+"\wallch", QStringList() << "--clock");
    }
    else QProcess::startDetached(qApp->applicationDirPath()+"\wallch");
    @

    God is Real unless explicitly declared as Integer.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Leon
      wrote on last edited by
      #3

      It seems it does nothing... If i do this:
      @qDebug() << qApp->applicationFilePath(), QStringList() << "--clock";
      QProcess::startDetached(qApp->applicationFilePath(), QStringList() << "--clock");@

      i get

      @Starting /home/citybong/Documents/wallch-build-desktop-Qt_4_8_3_in_PATH__System__Release/wallch...
      "/home/citybong/Documents/wallch-build-desktop-Qt_4_8_3_in_PATH__System__Release/wallch"
      /home/citybong/Documents/wallch-build-desktop-Qt_4_8_3_in_PATH__System__Release/wallch exited with code 0@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #4

        Are your app acting as an singleton?

        @
        int main(int argc, char ** argv)
        {
        if(argc > 1)sleep(5/seconds/);
        }

        void YourClass::YourFunction()
        {
        qDebug() << QProcess::startDetached(qApp->applicationFilePath(), QStringList() << "--clock");
        QTimer::singleShot(1,qApp,SLOT(quit()));
        }
        @

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Leon
          wrote on last edited by
          #5

          It works :)

          Is it necessary to sleep? Do you think there will be a conflict?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AcerExtensa
            wrote on last edited by
            #6

            If your app is singleton - where will be collisions... Or if user set to only run one instance of this app you will get collision, also if you save some data on exit, and load it on start you can get collision... so the sleep is simplest method to give the app some time to exit. Also if you save some data on exit, do it before startDetach to be on the save way...

            God is Real unless explicitly declared as Integer.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on last edited by
              #7

              You can also send application PID as the second argument and at the beginning of main loop check if app with this PID are closed, if not, sleep for 1 second and check again... so you can save some unneeded sleep seconds...

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Leon
                wrote on last edited by
                #8

                That is what i will do.. Gracias! :)

                [quote author="AcerExtensa" date="1352222532"]You can also send application PID as the second argument and at the beginning of main loop check if app with this PID are closed, if not, sleep for 1 second and check again... so you can save some unneeded sleep seconds...[/quote]

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on last edited by
                  #9

                  It is the same application, so why don't you have a "UI is hidden" mode that gets automatically triggered when started with --clock and just turn that on instead of restarting the application?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    alexandros
                    wrote on last edited by
                    #10

                    I understand your saying. But it will take much more RAM to keep the whole GUI up and running while you don't need it. By restarting the program you don't load the GUI at all and so there is no useless stuff in RAM.

                    [quote author="Tobias Hunger" date="1352320107"]It is the same application, so why don't you have a "UI is hidden" mode that gets automatically triggered when started with --clock and just turn that on instead of restarting the application?[/quote]

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      Leon
                      wrote on last edited by
                      #11

                      Anyone about the question of alexandros?

                      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