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.
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.
 
    
     
    
    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 
 
    
    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 04 '18 at 14:01
    Environment="DISPLAY=:0".
        – goldilocks
                May 04 '18 at 14:37
    graphical.target but in the [Install] section the parameter is called RequiredBy=.  But in this unclear situation for a first step I would prefer WantedBy because quote: "Often, it is a better choice to use Wants= instead of Requires= in order to achieve a system that is more robust when dealing with failing services." (man systemd.unit)
        – Ingo
                May 04 '18 at 15:11
    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 04 '18 at 15:16
    [Install] section. Does it run from a command line?
        – Ingo
                May 04 '18 at 15:19
    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
 
    
    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 07 '18 at 11:29