[Deprecated] Desktop App support - Qt5

:warning: 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.

1. Add qt5 dependencies to your snap

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 https://github.com/ubuntu/snapcraft-desktop-helpers.git.

  # 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.
  #    https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: qt
    <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.

2. Initialise desktop-specific functionality

Insert 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:

    adapter: full
    command: bin/qt5app
    - bin/desktop-launch

NOTE: If your application requires recent Qt or KDE libraries that aren’t available from Ubuntu LTS, the kde-frameworks content 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.

3. [optional] Add GTK theme integration

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 snapcraft.yaml file.

    plugin: nil
      - qt5-gtk-platformtheme

In the apps._app_name_ stanza, merge the following environment property:

      # Use GTK3 cursor theme, icon theme and open/save file dialogs.

In the plugs stanza, add the following plug definition:

  # Support for common GTK themes
  # https://forum.snapcraft.io/t/how-to-use-the-system-gtk-theme-via-the-gtk-common-themes-snap/6235
    interface: content
    target: $SNAP/data-dir/themes
    default-provider: gtk-common-themes
    interface: content
    target: $SNAP/data-dir/icons
    default-provider: gtk-common-themes
    interface: content
    target: $SNAP/data-dir/sounds
    default-provider: gtk-common-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.



I have a question for my app I need to set a specific version of QT and I need the qttools for that how I can achieve it following your guide?

If your Qt requirements are not provided by Ubuntu 16.04/18.04/KDE neon, I’m afraid you’ll have to build a Qt distribution from source and bundle it in your snap. The launchers provided in this article may help (with some custom patches to point to the right Qt paths).


The warning at the top of this post is somewhat misleading. The kde-neon extension used by the linked “Qt and KDE Frameworks applications” post is apparently only supported for the AMD64 platform and it also doesn’t work for classic snaps. So if you want to support other architectures or have a classic snap, you basically are still left with the Snapcraft Desktop Helpers project as your only choice.


Thanks! I updated the warning.

1 Like