Raspberry Pi QT project starts automatically

I have set up an interface with qt, how can I make it start automatically?

Table of contents

1. Generate the executable file of the qt project

2. Write a self-starting script

3. Restart the Raspberry Pi


1. Generate the executable file of the qt project

The executable file of the QT project is the .exe file. First open in qt , click the red box icon, select Release

Then click the "Project" icon, check the outline, and remember the address of the build directory.

Then click the hammer in the lower left corner to OK

In this way, you can view the generated .exe file in the directory just now, as shown in the following figure:

2. Write a self-starting script

Name it "autostart.desktop" and save it to the /home/pi/.config/autostart/ directory of the Raspberry Pi.

Specific steps:

Output the command in the command window:

Enter the .config directory

cd /home/pi/.config

Create the autostart directory

mkdir autostart

Enter the autostart directory

cd autostart

Create an autostart.desktop file (the file name can also be customized)

touch autostart.desktop

edit desktop file

nano autostart.desktop

The content of the desktop file is as follows:

[Desktop Entry]

Type=Application

Name=Your Qt Project Name

Exec=/home/pi/可执行文件的名字

Among them, " Your Qt Project Name" is the name of your Qt project, which can be chosen casually.

3. Restart the Raspberry Pi

The interface designed by Qt can be started automatically . .

Precautions:

1. Do not put the executable file too deep, just put it in the /home/pi folder, if you put it in another folder, you may not be able to open it if you do not have permission to boot.

2. After modifying the ui interface, the ui interface does not take effect: The principle of ui source file to interface display is generally to generate ui_.h from .ui and then compile, so the interface is not updated actually because of ui_*.h The file is not updated.

    Solution: delete the ui_*.h file and recompile it again.

Guess you like

Origin blog.csdn.net/ChenWenHaoHaoHao/article/details/130167266