Linux QT is published as a runnable program and desktop icon

1. Install linuxployqt first

2. Prepare the picture, create a new folder test, copy the application testApp developed by QT to the test path, find the test.png picture on the Internet, rename it to testApp.png; and copy the testApp.png picture to under the test path.

3. Generate the application and execute the command:

linuxployqt  testApp  -appimage

After completion, a series of files and folders such as AppRun, doc, plugins...default.desktop will be generated in the directory.

4. To test, copy the test folder to other computers where you want to run the program, and directly execute AppRun to run the program (./AppRun).

5. Generate desktop icons and rename default.desktop to testApp.desktop. Edit the content of testApp.desktop as follows:

[Desktop Entry]
Type=Application
Name=testApp
Exec=/home/xx/test/testApp
Icon=/opt/test/testApp.png
Comment= info 
Terminal=false

6. To test the shortcut, copy the modified testApp.desktop file to the desktop and the ~/.local/share/applications/ path, and grant executable permissions. Double-click testApp.desktop on the desktop to open it (or right-click to open it). When prompted with executable information, the file will become the desktop icon of testApp.png after confirmation. You can then run the program by double-clicking on the icon.

7. Publish into deb file:

①Create the folder deb under the ~ path

mkdir ~/deb

②Create the usr/src directory under the deb path, and copy the testApp folder and its contents to usr/src. The directory usr/src will be mapped to the specific path for subsequent deb file installation.

mkdir -p usr/src

cp -a ~/test/testApp  ~/deb/usr/src/

③Create DEBIAN under the deb path, and create a control file under DEBIAN. Edit the contents of the control file as follows

package:    testapp
Version:    1.0.0
Section:    utils
Priority:    optional
Architechture:    i386
Depends:
Installed-Size:    512
Maintainer:    xx
Description:    testapp-deb

Pay attention to the content of the first line: the content of package: must be in lowercase and cannot have underlines. You can use symbols such as underscores and dots.

④Execute the packaging command

dpkg -b . ~/testapp-1.0.0_i386.deb

⑤At this time, the testapp-1.0.0_i386.deb file can be generated under the /home/xx/ path and the application file can be sent to other computers. Execute the installation directory. After successful installation, you can find the testApp file under /usr/src/ of the installation computer. Note that the following commands require permissions.

sudo dpkg -i testapp-1.0.0-i386.deb

⑥Uninstall command, please note that when uninstalling, the package name is the content of the package: field of the control file.

sudo dpkg -r testapp

Supplement: In order to generate a desktop shortcut when installing the deb package, you need to modify the content of the testApp.desktop file under testApp and add the postinst file under the DEBIAN folder. The function of this file is the content of the script executed after installing the deb package.

Supplement 1: Add the prerm file under the DEBIAN file. The function of this file is to execute the script content of the file before uninstalling the installation package.

The modified content of testApp.desktop is as follows:

[Desktop Entry]
Type=Application
Name=testApp
Exec=/usr/src/testApp/testApp
Icon=/usr/src/testApp/testApp.png
Comment= info 
Terminal=false

The contents of the postinst file are as follows:

#!/bin/bash
cp /usr/src/testApp/testApp.desktop  /home/${SUDO_USER}/Desktop/
chmod +x /home/${SUDO_USER}/Desktop/testApp.desktop

The contents of the prerm file are as follows:

#!/bin/bash
filename=/home/${SUDO_USER}/Desktop/testApp.desktop
if [ -f ${filename} ]
then
    rm ${filename}
fi
exit 0

Guess you like

Origin blog.csdn.net/weixin_30072103/article/details/126742679