Unable to start packaged Qt5 application (segfault on QtWidget creation)

Scroll to TL;DR; to get to actual problem

I am trying to package our open source project using snapcraft, but given lack of examples for this kind of software I am having big troubles getting it to work.

Basically, it’s a C++ Qt4 / Qt5 application (can be compiled on both) with either WebKit or WebEngine, it has massive dependency tree, and consist of at least 8 separate binaries that need to be packaged together in a proper way so that it works.

I want packaging to be simple stupid, so that nobody who is doing the actual packaging needs to know ANYTHING about snaps. Basically I wanted to create a simple shell script that anyone can execute on Ubuntu and it produces a working snap, this shell script can be found here: https://github.com/huggle/huggle3-qt-lx/blob/snapfix/linux/snap/generate_snap.sh

That script will create a folder “tmp”, copy source code inside as well as snapcraft.yml and prepare it - I had some serious issues getting Qt plugins to work so I had to create a symlink inside of snap tree, which actually fixed it, that is visible in script.

The snapcraft.yml is IMHO looking pretty ugly, but it seems that removing anything from it will make it produce package that doesn’t run at all as libraries / dependencies are missing from it.

Now with this script and yaml file I am able to create actual snap file that can be installed and my application started, and all binaries seems to be packaged on proper places where it finds them, but it segfaults right when it tries to intialize first QtWidget (First window of application). Like if confining somehow prevented it from running properly?

TL;DR; I am able to package my program, but it doesn’t start - it’s getting segfault when it tries to create a QtWidget (window), I don’t know where exactly it crashes because I can’t figure out how to attach debugger to my application through that wrapper binary that is provided by snap.

Anyone has a clue what is wrong or how to do it right so that it works? Application, if compiled and not packaged by snap runs with no problems.

Here is the yaml file:

name: huggle
version: "3.2.0"
summary: Diff browser for MediaWiki based websites intended to deal with vandalism
description: Diff browser for MediaWiki based websites intended to deal with vandalism
confinement: strict
icon: src/Resources/huggle3_newlogo.png
epoch: 0
grade: stable

apps:
  huggle:
    command: huggle
    plugs:
        - unity7
        - x11
        - network
        - home
        - opengl
        - pulseaudio
        - browser-support

parts:
  application:
    plugin: cmake
    configflags:
      - -DQT5_BUILD=true
      - -DLINUX_SNAP=true
      - -DHUGGLE_EXT=true
    source: src/
    stage-packages:
      - libqt5gui5
      - libqt5core5a
      - libqt5webkit5
      - libqt5concurrent5
      - libqt5quickparticles5
      - libqt5widgets5
      - libqt5declarative5
      - libqt5quickwidgets5
      - libqt5network5
      - libqt5multimediaquick-p5
      - libqt5multimediawidgets5
    build-packages:
      - libgtk2.0-0
      - libdrm-dev
      - libegl1-mesa-dev
      - qtbase5-dev
      - libgl1-mesa-dev
      - libglu1-mesa-dev
      - libqt5opengl5-dev
      - libwayland-dev
      - libx11-dev
      - qtmultimedia5-dev
      - libqt5webkit5-dev
after: [desktop-qt5]

You should be using the desktop-launch script that comes with the desktop-qt5 part and sets up the environment, making it desktop-launch huggle.

Additionally, most of this is explained by running:

snapcraft define desktop-qt5

Which would produce this output:

Maintainer: 'Snapcraft community (https//forum.snapcraft.io)'
Description: Helpers for gtk2, gtk3, qt4 and qt5 or gnome-platform and glib minimal launchers.
It brings the necessary code and exports for binding and using those
desktop technologies in a relocatable fashion, enabling binding with
global desktop theme, icon theme, image caching, fonts, mimetype handlers
application global menu and gsettings integration.
It also brings basics ubuntu dependency packages.
.
Usage:
  1. add "after: [desktop-<technology>]" to your launcher:
     - gtk2, gtk3, qt4 and qt5 corresponds to their respective toolkit
       main dependencies and default choices.
     - gnome-platform is similar to gtk3 without the extra depends, it's
       meant to be used with the gnome platform which already includes those.
     - glib-only enables to compile mime types and gsettings infos. If you
       added your own graphical drivers, it will link them as well.
  2. prepend your command with "desktop-launch", like:
     commands: "desktop-launch foo" if foo is in $PATH. You can as well
     specify: "desktop-launch $SNAP/foo".
  3. add needed plugs to your application:
     - for graphical application:
       plugs: [x11 (or unity7 for appmenu integration)]. Think about adding
       opengl if you need hw acceleration.
     - if your application needs access to sound:
       plugs: [pulseaudio]
     - accessing to user's home directory:
       plugs: [home]
     - read/write to gsettings:
       plugs: [gsettings]
     - use of the shared platform snap content, first define the plug:
         plugs:
           gnome318-platform:
             interface: content
             target: gnome-platform
             default-provider: gnome318-udt:gnome318-platform
       and then make your apps use it:
         plugs: [gnome318-platform]
       Note that an empty "gnome-platform" directory will be created for you
       in your snap.


desktop-qt5:
  build-packages:
  - qtbase5-dev
  - dpkg-dev
  make-parameters:
  - FLAVOR=qt5
  plugin: make
  source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
  source-subdir: qt
  stage-packages:
  - libxkbcommon0
  - ttf-ubuntu-font-family
  - dmz-cursor-theme
  - light-themes
  - adwaita-icon-theme
  - gnome-themes-standard
  - shared-mime-info
  - libqt5gui5
  - libgdk-pixbuf2.0-0
  - libqt5svg5
  - appmenu-qt5
  - locales-all

Also take into account that by using the desktop-qt5 part, most of the things declared in your specific part are not needed as the desktop-qt5 part provides all the basic dependencies to build a Qt5 application.

that seems to work now, thanks

Another problem I have is that icon doesn’t seem to work, in produced snap I can see /meta/gui/icon.png which is icon of my application but when I install snap, the application doesn’t have any icon in OS menu. Is .png bad format?

desktop file contains Icon=/usr/local/share/huggle/huggle3_newlogo.png which obviously can’t work as snap doesn’t store data in there.

You can do Icon=${SNAP}/meta/gui/icon.png to use the same icon as is used in the same. Alternatively Icon=${SNAP}/share/huggle/huggle3_newlogo.png can work as well.

Alternatively, if snapcraft.yaml has a ‘desktop’ entry under your app’s definition pointing to the desktop file , snapcraft will automagically translate absolute paths to prepend ${SNAP}. See e.g. how it was done for webbrowser-app.

1 Like