2

I'm trying to run Qt GUI application automatically when booting Raspberry Pi using Openbox but have problems and can't make it work. Steps I did:

  • run raspi-config and changed Boot Options to Console Autologin
  • in /etc/rc.local I added startx & before exit 0
  • in /etc/X11/xinit/xinitrc I commented . /etc/X11/Xsession and added exec openbox-session
  • in /etc/xdg/openbox/autostart I added /home/pi/Wt/WidgTest & which is my app.

OpenBox runs because I have black screen with cursor in it and can access it's menus but my application doesn't. Can someone tell me what I do wrong?

Thanks.

---Edit---

As suggested in the comments I tried to used systemd unit files to do this. First I made an unit file for xsession:

[Unit]
Description=session

[Service]
Type=idle
ExecStart=startx

[Install]
WantedBy=multi-user.target

Then I made the unit file to run openbox session:

[Unit]
Description=Openbox
After=session.service

[Service]
Type=idle
ExecStart=/usr/bin/openbox-session

[Install]
WantedBy=multi-user.target

And unit file to run my app:

[Unit]
Description=MyApp
After=openbox.service

[Service]
Type=idle
ExecStart=/home/pi/Desktop/MyApp/MyApp

[Install]
WantedBy=multi-user.target

The openbox service fails to run. systemctl status openbox.session output:

openbox.service - Openbox
   Loaded: loaded (/lib/systemd/system/openbox.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2020-12-08 06:52:56 GMT; 46s ago
  Process: 415 ExecStart=/usr/bin/openbox-session (code=exited, status=1/FAILURE)
 Main PID: 415 (code=exited, status=1/FAILURE)

Dec 08 06:52:51 raspberrypi systemd[1]: Started Openbox.
Dec 08 06:52:56 raspberrypi openbox-session[415]: Openbox-Message: Failed to open the display from the DISPLAY environment variable.
Dec 08 06:52:56 raspberrypi systemd[1]: openbox.service: Main process exited, code=exited, status=1/FAILURE
Dec 08 06:52:56 raspberrypi systemd[1]: openbox.service: Failed with result 'exit-code'.

UPDATE with info from a comment:
I'm trying to do is to boot raspberry to my app. I want to display my splashscreen and then run my app. So I switched boot to Console Autologin and try to run Openbox just for my application. At first I tried to do that by running my app directly in the framebuffer, but I had problem with rotating my app and displaying gradients so I'm looking for another alternative.

6
  • You should use a systemd Unit file to start the service. Have a look at Questions tagged (systemd-startup).
    – Ingo
    Dec 7, 2020 at 12:55
  • So I should make unit files for xsession then for openbox and then my app?
    – Piotr
    Dec 7, 2020 at 13:42
  • As far as I understand you can start your application from the command line. If so you are usually able to just ExecStart= this command within a Unit file with some additional statements to get the same environment of the command line. systemd manages GUI resources by itself using the graphical.target but I don't know if there are special issues with OpenBox and/or with your setup. Can you please add the working command line command to the question?
    – Ingo
    Dec 7, 2020 at 14:14
  • Added what I tried with systemd.
    – Piotr
    Dec 8, 2020 at 7:17
  • I do not understand what you are trying to do with OpenBox. What operating system, what version do you use?
    – Ingo
    Dec 9, 2020 at 1:33

3 Answers 3

2

Raspberry Pi OS Desktop based on Buster runs the LXDE Desktop environment by default. Its main component is the Openbox Window Manager. So if you run a fresh flashed RaspiOS image with Desktop you have the Graphical User Interface managed by Openbox. There is nothing to do additional.

With this environment (use a fresh flashed OS?) just start your application with a systemd Unit file. systemd will manage the GUI for your application. Create a new service with:

rpi ~$ sudo systemctl edit --force --full YourApp.service

In the empty editor insert these statements, save them and quit the editor:

[Unit]
Description=Your Application
After=graphical.target

[Service]
User=pi
Environment=DISPLAY=:0.0
ExecStart=/home/pi/Desktop/MyApp/MyApp

[Install]
WantedBy=graphical.target

Enable it and reboot:

rpi ~$ sudo systemctl enable YourApp.service
rpi ~$ sudo systemctl reboot

I don't know anything about your application so it may be possible that you have to set some additional options. Just give feedback if it doesn't work on the first try.

2

Unless you have a compelling reason not to use the default graphical environment, I would rather configure your Pi to autologin to desktop via raspi-config, and then edit the /etc/xdg/lxsession/LXDE-pi/autostart file to autostart your app, and remove stuff you don't want like lxpanel.

Running xserver from systemd is possible but far from painless. Ironically, your unit named session does not provide any actual session xserver could take over.

If you want to go this route, try setting allowed_users=anybody in Xwrapper.config for a start. You can also set up a session, which means you'll need to run lightdm/lxsession or some sort of replacement.

1

(I know this is old but for the record)

You don't need X11 or Wayland. Qt can be told via the environment to render direcly by setting QT_QPA_PLATFORM=eglfs

You can also tell it to hide the cursor by setting QT_QPA_EGLFS_HIDECURSOR=1

Since someone else asked me this morning I created a complete minimal PySide / PyQt application that runs directly on the 7" display without any X11 or desktop code. You can start with the Lite version of Rasbperry Pi.

The code and installation instructions are here: https://github.com/lbt/python-gui

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.