1

Possible Duplicate:
running a qt application at startup

How can I run a qt program at startup so that the user won't see the desktop at all? I am building my program in linux and I want to distribute it to linux users. I want to add that code to my app, because the customers don't have any understanding about linux. I found that QSettings can do that, is it true? What about QService? Can we use a simple code like this?

QSettings  a;
A.setpath(IniFormat,SystemScope,/etc/xdg)
Community
  • 1
  • 1
Erfan Tavakoli
  • 336
  • 1
  • 6
  • 14
  • 1
    Can you clarify on "unable to see the desktop at all"? Do you mean that the computer will start and run your program instead a login manager? Or you need something else? Like preventing user to do some stuff? – infiniteRefactor Dec 25 '12 at 13:40
  • i mean: a user log in and then my app run automatic and become full screen, (i know how to fullscreen) – Erfan Tavakoli Dec 25 '12 at 13:57
  • This has nothing to do with `QSettings`. It is just a matter of making your app start in full screen, and placing it into a startup location on your system – jdi Dec 25 '12 at 17:57

2 Answers2

5

QSettings has zero relevance to this and QService is for Symbian devices. In fact, your question has nothing to do with Qt.

What you need to do is place a *.desktop shortcut or link to the application in the user's startup folder. See:

http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html.

For example, if I want to start the application /opt/myapp/myapp_executable at login, I would create a myapp.desktop file with the following contents:

[Desktop Entry]
Exec=/opt/myapp/myapp_executable

and put it in my ~/.config/autostart directory.

If you want it to be executed for every user at login, then you'd put it in /etc/xdg/autostart/. But again, check the XDG site because the directory can be different if an XDG environment variable is set that overrides the default.

Your question really belongs on http://superuser.com

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
  • I'd rather suggest to pretend as a window manager/DE, so there will be no desktop at all. – Dmitry Melnikov Dec 25 '12 at 17:08
  • @DmitryMelnikov It doesn't look like the OP would know how to write such an app (if he knew, he probably wouldn't have asked the question.) It's a Qt app, so most probably it depends on a running desktop with all its daemons and services (Window manager, D-Bus, Phonon, Gnome-keyring, etc.) – Nikos C. Dec 25 '12 at 17:11
  • 1
    ok, but if i build my app, and give it to my friend, so he put app in another directory , so how can i handle that? he doesn't know anything about linux, he just want to start exacutabl – Erfan Tavakoli Dec 25 '12 at 19:09
  • @ErfanTavakoli Then you should offer either an installer, or a package (*.deb, *.rpm, or whatever this specific Linux distro uses) that sets this up correctly. This isn't any different from Windows, really. – Nikos C. Dec 25 '12 at 20:27
  • i go to the ~/.config/ but there isn't any folder with name "autostart" then i make a folder with this name and copy my .desktop file to it . but my app never run in startup. what is the problem. – Erfan Tavakoli Dec 26 '12 at 06:12
  • @ErfanTavakoli Check the XDG docs and see if a variable is defined, and also check the docs of your desktop (is it Gnome?) – Nikos C. Dec 26 '12 at 07:20
2

If you are using linux, use cron to launch your program, add something like this to crontab:

@reboot /path/to/program

Or to launch it at user login, append /path/to/program to ~/.bashrc or ~/.bash_profile

  • That won't work, because the desktop isn't running yet when cron executes it. – Nikos C. Dec 25 '12 at 16:56
  • 1
    you can set cron to launch an `at` command to delay the launch, something like `at -f /path/to/program now + 1 hour` –  Dec 25 '12 at 16:59
  • It won't launch it at login time though. It's a kludge, at best. – Nikos C. Dec 25 '12 at 17:04
  • @NikosC. sorry, I don't understand what you are trying to achieve, could you try to explain it some other way? –  Dec 25 '12 at 17:06
  • What I'm trying to say is that cron cannot execute programs at XDM login time. Either it'll do it too early, or too late. – Nikos C. Dec 25 '12 at 17:08
  • fair enough, didn't notice that –  Dec 25 '12 at 17:29