How to Package a QT application as a snap application--snapcraft scriptlets application Example

Source: Internet
Author: User

In our previous article, "How to Package a qmake Ubuntu mobile app as a snap application", we learned how to package a Qmake project into a snap application. In today's tutorial, we use QT Creator to create a project and ultimately package our app as a snap project. In the process of packaging, we can experience the scriplets in Snapcraft.


1) Create a QT HelloWorld project
First, we open our QT Creator:






This allows us to create one of the simplest HelloWorld applications.

2) Create a Snapcraft.yaml file
In the root directory of the project, we enter the following command:

$ snapcraft Init
The above command will generate a directory called snap for us in the current directory (Snapcraft version 2.26, which did not create this snap directory).
liuxg@liuxg:~/snappy/desktop/qtapp$ tree-l 3
.
├──main.cpp
├──mainwindow.cpp
├──mainwindow.h
├──mainwindow.ui
├──qtapp.pro
├── Qtapp.pro.user
├──readme.md
└──snap
    └──snapcraft.yaml

The schema for all files is as shown above. We can modify this Snapcraft.yaml file by editing:
Snapcraft.yaml
Name:qthello 
version: ' 0.1 ' 
summary:a demo for qt Hello app
Description: |
  This is a QT app demo

grade:stable 
confinement:strict 

Apps:
  Qthello:
    command:desktop-launch $ Snap/opt/myapp/qtapp
    plugs: [Home, Unity7, X11]

parts:
  project:
    plugin:qmake
    Source:.
    QT-VERSION:QT5
    project-files: [Qtapp.pro]
    Install: |
      install-d $SNAPCRAFT _part_install/opt/myapp
      INSTALL qtapp $SNAPCRAFT _part_install/opt/myapp/qtapp

  Integration:
    plugin:nil
    stage-packages:
     -libc6
     -libstdc++6
     -Libc-bin after
    : [ DESKTOP-QT5]

Here, we must point out that:
    Install: |
      install-d $SNAPCRAFT _part_install/opt/myapp
      INSTALL qtapp $SNAPCRAFT _part_install/opt/myapp/qtapp

Since there is no corresponding code in the original Qtapp.pro file, let's get to the installation of our Qtapp application file. Here we use the install above for our application. According to the description in Scriplets:
"Install" The

install Scriptlet is triggered after the build step of a plugin.

The scripts will automatically be executed automatically after the build. It first creates a directory called MyApp and then installs our binary execution file Qtapp in the build directory into the MyApp directory. This ultimately forms our snap package.
We install the Qthello application and execute:




The source code of the whole project is: Https://github.com/liu-xiao-guo/qthello. Read more: H TTPS://GITHUB.COM/LIU-XIAO-GUO/WECHAT1
In this snap application, we package the dependencies of all QT libraries into one package, so that our final snap packet size is large. If developers want to reduce the size of this QT application, developers can refer to the article "using the Platform interface provided by Ubuntu-app-platform to reduce QT application size" to reduce the size of the entire application.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.