Search code examples
c++linuxqtautostart

Qt C++ application: self autostart installation in Linux


I'm porting some Qt Windows/VC++ code to Linux/GCC. The application can add it's own shortcut to the Windows Autostart folder so the application starts after login.

I want to do the same in Linux. I'm using Kubuntu 15.10 but the solution should work for virtually all (or at least most) Linux variants out there. And it should work without super user rights (or it should request the rights automatically).

I searched the web and found two solutions:

  1. Add a desktop entry file to $HOME/.config/autostart
  2. Add a symbolic link to /etc/init.d/

Will they both work in all Linux distributions? What are the differences? Which is to be preferred?

Also I would like to know if I should do that by programmatically running a shell command or if there is some native API I could use in C/C++ (including easy error detection).


Solution

  • You can add application in various ways.

    1. Via linux init system. For newest linux OS systemd is a standard. In this case your need to create systemd unit for your application
    2. Via desktop manager, such as gnome, kde and possible others. In this case you need also create specification for autostarting your app.
    3. Via bash files

    I think, prefered way via systemd unit, because now this is standard way for starting process at boot time and for special user, if need.