Cannot create a UI: please install zenity or kdialog

I’m trying to create a snap package for a pre-built Qt5 application, which contains all required libraries already. That is, it works well in a portable manner as well as an AppImage.

Here is my snapcraft.yaml:

name: myqt5prebuiltapp
version: 1.0.0
summary: App summary
description: |
  App description
grade: stable
confinement: devmode
base: core18

    extensions: [ gnome-3-34 ]
    command: myqt5prebuiltapp
      - home
      - opengl
      - network
      - network-bind
      - pulseaudio
      - x11
      - desktop
      - desktop-legacy
      - wayland
      - gsettings

    plugin: dump
    source: https://url/to/my/app-Linux-x86_64.tar.gz
    source-type: tar
      - libxkbcommon0
      - libgl1
      - libgl1-mesa-dri
      - libgl1-mesa-glx
      - libasound2
      - libgdk-pixbuf2.0-0
      - libpango-1.0-0
      - libpangocairo-1.0-0
      - libpangoft2-1.0-0
      - libfontconfig1
      - unity-gtk2-module
      - libglib2.0-bin
      - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-standard
      - libgtk2.0-0

On app starts, although the following messages appear, most functions of the app still works.

Cannot load module /snap/documentnode/x1/gnome-platform/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules/ /snap/documentnode/x1/gnome-platform/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules/ undefined symbol: gdk_display_get_default_seat
/snap/documentnode/x1/gnome-platform/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules/ does not export GTK+ IM module API: /snap/documentnode/x1/gnome-platform/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules/ undefined symbol: gdk_display_get_default_seat
ERROR: /snap/documentnode/x1/gnome-platform/usr/lib/x86_64-linux-gnu/libgtk-3-0/gtk-query-immodules-3.0 exited abnormally with status 1
Gtk-Message: 08:31:59.188: Failed to load module "canberra-gtk-module"
Gtk-Message: 08:31:59.194: Failed to load module "canberra-gtk-module"

When the app tries to open an external file URL (using QDesktopServices::openUrl("file url")), the following error message appears, and the file cannot be opened.

user-open error: cannot create a UI: please install zenity or kdialog

It works properly when it opens a web URL, QDesktopServices::openUrl(""). After some investigation, I guess when opening an external file URL, QDesktopServices::openUrl will use xdg-open command. Before that, the snap app needs to show a dialog to ask users’ permission open the file, but it cannot find a UI library to show the dialog.

I tried add zenity and kdialog as stage-packages, and tried different ways from my Google search, but the same issue still exists.

Can any one point me the right direction about how to enable zenity or kdialog in the snap pacakge? Many thanks in advance.

Refer Inform users with custom dialogs for Zenity integration info.

Thank you Lin-Buo-Ben,

I tried exactly the same post you mentioned.

I added

  # Integrate custom dialogs in your snap - doc -
    plugin: nil
      - zenity
      - usr/bin/zenity
      - usr/share/zenity/*


  # Fix resource relocation problem of zenity part
    symlink: $SNAP/usr/share/zenity

to the above snapcraft.yaml, but still got the same error.

I’m new to snapcraft, shall I configure anything special in snapcraft.yaml for gnome-platform content sharing?

Looks like zenity has to be installed on the host machine.

After I installed it via the command below:

sudo apt install zenity

The openUrl method opened an external file successfully.