-1

This question already has an answer here:

I want to make my qt project run while booting raspberry pi3. When I searched on the web there is a solution for python. Eventhough I put some code on rc.local, this did not solve my problem.

The application has a GUI and the OS is Raspbian Stretch.

marked as duplicate by goldilocks May 7 '18 at 11:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    This will be dependent on the OS you are running on your Pi. You should add this info to your question. – Glen Yates May 4 '18 at 13:25
  • What happens when you add it to the rc.local file? Have you been able to log the output, and does that reveal anything? – Aurora0001 May 4 '18 at 13:43
  • Since you are using QT, you might want to make it explicit whether this is a GUI application you expect to open in the foreground, or something that can run in the background (and if so whether it is finite event or a persistent daemon). – goldilocks May 4 '18 at 13:54
  • Application has GUI and the OS is Raspbian Stretch. – aysenur May 4 '18 at 14:25
  • Thanks. In future edit information into your question and leave a comment @goldilocks to let me know. – goldilocks May 4 '18 at 14:34
3

I guess you are using Raspbian Stretch. This comes with systemd so you should start your qt project as service. First create a new service:

rpi3 ~$ sudo systemctl edit --force --full my_qt_project.service

Insert this statements with your settings, save them and quit the editor:

[Unit]
Description=My Qt Project Service

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/home/pi/my_qt.project

[Install]
RequiredBy=graphical.target
# Look at the comments, maybe you can use
#WantedBy=graphical.target

Check the new service:

rpi3 ~$ systemctl status my_qt_project.service
● my_qt_project.service - My Qt Project Service
   Loaded: loaded (/etc/systemd/system/my_qt_project.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Now you can enable and test your service:

rpi3 ~$ sudo systemctl enable my_qt_project.service
rpi3 ~$ sudo systemctl start my_qt_project.service

Here are some commands that may help. After editing you must restart the service to take effect.

rpi3 ~$ systemctl status my_qt_project.service
rpi3 ~$ systemctl cat my_qt_project.service
rpi3 ~$ sudo systemctl edit --full my_qt_project.service
rpi3 ~$ sudo systemctl restart my_qt_project.service


references
[1] man systemd.unit
[2] Running a script after an internet connection is established
[3] No access to USB port, when running python script on boot

  • That this is a QT app implies it is has a GUI which will require the X server, etc. Are you sure this approach will work as is for that? I'm guessing it doesn't... – goldilocks May 4 '18 at 13:52
  • To suggest a solution to the problem goldilocks pointed out, you could guarantee that the DE is ready by replacing the line beginning with WantedBy by Requires=graphical.target. See this graph to see the rough order of units being loaded; WantedBy=multi-user.target is almost certainly too early. – Aurora0001 May 4 '18 at 14:01
  • I did the same as you said. Service started without error but does not start my application. In Line ExecStart=/home/pi/my_qt.project, I wrote the path of my executable file not the pro file. Is this true? Later I changed the WantedBy.. line as told in the comment. I wrote Requires=graphical.taget instead of this. But now gives error while checking status. The error is; Active:failed(Result: signal) Main process exited, code=killed, status=6/ABRT – aysenur May 4 '18 at 14:22
  • 1
    @Ingo I had thought that WantedBy and RequiredBy means that your unit must run before the specified one, whereas Wants and Requires run after the specified (which is probably what you want, as you need the GUI to be ready before running). You're right that Wants is more fault tolerant, but in this case I might suggest that it'd be better for the unit to fail than to try and run after graphical.target failed, which would happen if Wants was used. Still, it's an edge case and probably won't matter. – Aurora0001 May 4 '18 at 15:16
  • 1
    @aysenur as you see at the comments your information is to small. There are too many possibilities we have to guess. Maybe there are other services that have to start before or after your application. You have to examine environment/rights for your application. Please correct the [Install] section. Does it run from a command line? – Ingo May 4 '18 at 15:19
0

Thank you for your answers. Adding the execution path of the application with sudo command ( @sudo /path/to/QtPro ) to the following file solved the problem. ~/.config/lxsession/LXDE-pi/autostart

  • The sudo is likely superfluous there unless the application itself requires privileges (i.e., the pi user must use sudo to start it normally). Also note this will only work at boot if autologin for the pi user is enabled. It is probably a better choice than using systemd for this kind of thing. – goldilocks May 7 '18 at 11:29

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