Close application and relaunch but with an argument..?
-
So let's say we have an app called wallch (wallpaper changer).. You can open wallch with command:
@wallch@but u can also in order not to open the gui run:
@wallch --clock@and it will start changing wallpapers without showing the gui..
Lets say we have opened wallch's gui and we have started the wallpaper changing mode.. and we want the wallpaper changing mode still run when wallch closed.. So what we want is in order to free up some memory to close wallch and after 1-2 seconds run
@wallch --clock@Our bad solution is this:
@system("wallch --clock > /dev/null 2>&1 &")@but i am sure there must be something else... :/
-
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");
@ -
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@ -
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()));
}
@ -
It works :)
Is it necessary to sleep? Do you think there will be a conflict?
-
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...
-
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...
-
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]
-
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?
-
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]
-
Anyone about the question of alexandros?