This tutorial is outdated. See Qt 5 and KDE Frameworks applications for a much easier way to snap Qt 5 applications.
This tutorial should only be used when you want to support architectures other than amd64, or for classic snaps.
This guide explains the recommended way to make a qt5 application function correctly inside a snap. These instructions need to be applied in addition to the instructions for creating a snap in your programming language. For example, if your application uses the C programming language and Qt5, you also need to follow the instructions for snapping a C/C++ application.
The Snapcraft Desktop Helpers project provides the
desktop-qt5 part to include the Qt5 dependencies in your snap. It also includes the
desktop-launch script to initialise the desktop-specific functionality before your application launches.
Copy the definition of the
desktop-qt5 part from the Snapcraft Desktop Helpers
snapcraft.yaml into your Snapcraft recipe, in the
parts section. Change the
source property of this part to
# This part installs the qt5 dependencies and a `desktop-launch` script to initialise
# desktop-specific features such as fonts, themes and the XDG environment.
# It is copied straight from the snapcraft desktop helpers project. Please periodically
# check the source for updates and copy the changes.
<copy the rest of this part from the desktop helpers snapcraft.yaml>
NOTE: In order to keep the integration up-to-date for the best user experience, you should check if the definition in the Snapcraft desktop helpers repo has been changed periodically.
bin/desktop-launch into the app’s command chain.
command: bin/desktop-launch qt5app
If you’re using the
full adapter, insert the
bin/desktop-launch launcher into the list of the
command-chain key of the
apps._app_name_ property instead:
NOTE: If your application requires recent Qt or KDE libraries that aren’t available from Ubuntu LTS, the
kde-frameworkscontent and SDK snaps might be useful. Please take a look at KDE Snap Guide to see how to use this SDK. This SDK only supports the AMD64 processor architecture.
Snapped Qt applications by default don’t use the UI theme of the operating system they are running on. You can make your snapped application adapt to most common UI themes using the
gtk-common-themes content snap and the
gtk3 Qt Platform theme.
Add the following
qt5-gtk-platform part into the
parts section of your
apps._app_name_ stanza, merge the following
# Use GTK3 cursor theme, icon theme and open/save file dialogs.
plugs stanza, add the following plug definition:
# Support for common GTK themes
Now your applications will use the icon theme, cursor theme and open/save file dialogs of the desktop it runs on. The colors of your applications will also adapt to the GTK theme colors of the operating system.
You can take a look at the
snapcraft.yaml file of
keepassxc for a complete example of a qt5 snap.