Start Qt at boot without X11/wayland with systemd

Start your Qt application as soon as the OS comes available.

orangepi | 2023-11-11
At home

Sometimes you want to start your Qt application as soon as it is possible to run, after the computer boots. And you may also want to automatically restart when it crashes. Finally, you also want to run this application 'standalone', without using a desktop environment to save some resources. This setup is ideal for public facing systems.

The above can be achieved via a systemd unit file. Example:

/etc/systemd/system/test.service

[Unit]
Description=Persistent test GUI service
After=network.target

[Service]
WorkingDirectory=/home/myuser/
User=myuser
Restart=on-failure
RestartSec=5
Environment="QT_QPA_FB_HIDECURSOR=1"
Environment="QT_QPA_PLATFORM=linuxfb"
ExecStart=/home/myuser/app/build/bin/application

[Install]
WantedBy=multi-user.target

Change the paths as you see fit and manage your application via systemd:

systemctl daemon-reload   # reload systemd configuration(s)
systemctl start test      # start the application
systemctl enable test     # mark the application to start on boot

Disabling the console

To prevent the tty console from appearing after boot, use systemctl mask getty@tty1.service.