Linux packages Qt programs as AppImage packages

Foreword

In the Linux environment, after developing a Qt program, it also needs to be made into an installation package or executable file for distribution. Here is an introduction to using linuxdeployqt to package Qt programs into .AppImage applications (similar to Windows’ green installation-free software)

Environment configuration

Configure Qt environment variables

This step is to enable the linuxdeployqt tool to recognize the Qt environment. Edit the bashrc file

vim ~/.bashrc

Add your own Qt environment after the last line

#QT ENV
export QTDIR=/home/leo/Qt/5.15.2/gcc_64

export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=$QTDIR/plugins:$QT_PLUGIN_PATH
export QML2_PATH=$QTDIR/qml:$QML2_PATH

Effective immediately

source ~/.bashrc

verify

qmake -v

Configure linuxdeployqt

Go to linuxdeployqt to download the linuxdeployqt-continuous-x86_64.AppImage released by release

Then grant executable permissions, change the name to make it easier to use, and put it under the path /usr/local/bin for easy use anywhere.

chmod 777 linuxdeployqt-continuous-x86_64.AppImage
mv linuxdeployqt-continuous-x86_64.AppImage linuxdeployqt
sudo mv linuxdeployqt /usr/local/bin

have a test

linuxdelpoyqt --version

piMs7NQ.png

Configuring AppImageKit

Go to AppImageKit to download appimagetool-x86_64.AppImage

Likewise, add execution permissions:

chmod 777 appimagetool-x86_64.AppImage

Install patchelf

Just install patchelf directly with apt

sudo apt install patchelf

Packaging

Copy the application to the output directory and run the command (here, we take the QClipboard executable program as an example):

leo@leo-VirtualBox:~/Desktop/output$ linuxdeployqt QClipboard -appimage
linuxdeployqt (commit 6fcaf74), build 55 built on 2023-09-23 13:33:41 UTC
Not using FHS-like mode
app-binary: "/home/leo/Desktop/output/QClipboard"
appDirPath: "/home/leo/Desktop/output"
relativeBinPath: "QClipboard"
ERROR: Desktop file missing, creating a default one (you will probably want to edit it)
ERROR: Icon file missing, creating a default one (you will probably want to edit it)
qmakePath 3= ""
appimagetool, continuous build (commit 8bbf694), build <local dev build> built on 2020-12-31 11:48:33 UTC
fatal: not a git repository (or any parent directory): .git
Failed to run 'git rev-parse --short HEAD: Child process exited with code 128 (code 128)
Desktop file: /home/leo/Desktop/output/default.desktop
Categories entry not found in desktop file
.desktop file is missing a Categories= key

Then you can see that some files are generated in the output directory

lrwxrwxrwx 1 leo leo 10 November 3 21:31 AppRun -> QClipboard
-rw-rw-r-- 1 leo leo 123 Nov 3 21:31 default.desktop
-rw-rw-r-- 1 leo leo 0 November 3 21:31 default.png
drwxrwxr-x 6 leo leo 4096 November 3 21:31 doc
drwxrwxr-x 2 leo leo 4096 November 3 21:32 lib
drwxrwxr-x 7 leo leo 4096 November 3 21:32 plugins
-rwxrwxr-x 1 leo leo 157512 November 3 21:30 QClipboard
-rw-rw-r-- 1 leo leo 145 Nov 3 21:32 qt.conf
drwxrwxr-x 2 leo leo 4096 November 3 21:32 translations

Modify desktop files

We need to modify the default generated desktop file

leo@leo-VirtualBox :~/Desktop/output$ cat default. desktop
[Desktop Entry]
Type=Application
Name=Application
Exec=AppRun %F
icon=default
Comment=Edit this default file
Terminal=true

You can view the desktop file specifications for modification

Here, the default.desktop file is renamed to the QClipboard.desktop file and modified to the following content:

[Desktop Entry]
Categories=System; Office;
Type=Application
Keywords=clip; clipboard;
Name=QClipboard
Exec=AppRun %F
icon=logo
Comment=A cross-platform clipboard tool that allows selecting items from clipboard history to paste.
Terminal=true

Then deleted the redundant folders, and the final effect is as follows:

Generate appimage application

Use appimagetool to generate appimage applications.

Execute ./appimagetool-x 86_64. AppImage output/. The output after it is our output directory.

Note: Since the downloaded appimagetool-x 86_64. AppImage application is not placed in the /usr/local/bin path, it cannot be executed directly.

leo@leo-VirtualBox :~/Downloads$ ./appimagetool-x 86_64. AppImage ~/Desktop/output/
appimagetool, continuous build (commit 8 bbf 694), build <local dev build> built on 2020-12-31 11:48:33 UTC
/home/leo/Desktop/output/QClipboard. desktop: hint: value "System; Office;" for key "Categories" in group "Desktop Entry" contains more than one main category; application might appear more than once in the application menu
Using architecture x 86_64
/home/leo/Desktop/output should be packaged as QClipboard-x 86_64. AppImage
WARNING: AppStream upstream metadata is missing, please consider creating it
         in usr/share/metainfo/QClipboard.appdata.xml
         Please see https://www.freedesktop.org/software/appstream/docs/chap-Quickstart.html#sect-Quickstart-DesktopApps
         for more information or use the generator at http://output.jsbin.com/qoqukof.
Generating squashfs...
Parallel mksquashfs: Using 6 processors
Creating 4.0 filesystem on QClipboard-x 86_64. AppImage, block size 131072.
[================================================== =======================/] 530/530 100%

Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
compressed data, compressed metadata, compressed fragments,
compressed xattrs, compressed ids
duplicates are removed
Filesystem size 25011.83 Kbytes (24.43 Mbytes)
39.56% of uncompressed filesystem size (63223.96 Kbytes)
Inode table size 2316 bytes (2.26 Kbytes)
55.20% of uncompressed inode table size (4196 bytes)
Directory table size 861 bytes (0.84 Kbytes)
52.25% of uncompressed directory table size (1648 bytes)
Number of duplicate files found 0
Number of inodes 69
Number of files 59
Number of fragments 12
Number of symbolic links 2
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 8
Number of ids (unique uids + gids) 1
Number of uids 1
root (0)
Number of gids 1
root (0)
Embedding ELF...
Marking the AppImage as executable...
Embedding MD 5 digest
Success

Please consider submitting your AppImage to AppImageHub, the crowd-sourced
central directory of available AppImages, by opening a pull request
at https://github.com/AppImage/appimage.github.io

Then you can see the generated QClipboard-x 86_64. AppImage package in the same path as appimagetool-x 86_64. AppImage

Execute test

QClipboard application successfully executed

Note that when you distribute it to others, you need to add execution permissions to run it.

Summary

The above is the entire process of packaging Qt programs into AppImage programs under Linux systems.

At the same time, you are welcome to star the cross-platform clipboard tool: https://github.com/L-Super/QClipboard

https://blog.csdn.net/zyhse/article/details/106381937

https://www.cnblogs.com/linuxAndMcu/p/11016322.html

UnityLaunchersAndDesktopFiles – Community Help Wiki (ubuntu.com)

desktop file specifications | DeepinWiki

icon-theme-spec