To create a built-in QML app, you must write the source code and prepare the required configuration files.
For easier understanding, the process to create a built-in QML app is explained using a sample app in Sample Code Repository. The sample app has the following features:
When the app is launched, it displays a “Hello, QML Application!!” message on the screen.
When the user clicks on the screen, it calls the com.webos.service.systemservice/clock/getTime method. “UTC” time on the response is printed on the screen.
Prints logs in the following conditions:
When it is first launched and relaunched, outputting the params value which is passed on the launch method of System and Application Manager (SAM)
When windowState changed.
The directory structure of the sample app must be as follows:
Line(2) : Import WebOSServices to call system services via luna-service.
Line(3) : Import Eos.Window to use WebOSWindow QML component.
Line(4) : Import PmLog to print logs.
Line(6~62) : Declare a WebOSWindow object with child objects.
Line(7~13) : Set WebOSWindow properties and size and color.
Line(14): Set the displayAffinity property so that the app can be launched on the display corresponding to the displayAffinity value passed as a launch parameter.
Line(16~22) : Declare a Text object and string.
Line(24~27) : A QML app (with the type “qml” on appinfo.json) is launched and registered to SAM by qml-runner. Through this process, the QML app can receive the parameters passed with the launch method call as params. With each launch method call, onLaunchParamsChanged is called even if the value of params ds not change from that of the previous call. For details of PmLogLib usage, refer to Using PmLogLib in QML.
Line(29~47) : Declare a Service object to call systemservice’s getTime method. If the object receives the response, the app prints the UTC time on the screen.
Line(49~52) : When the user clicks on the screen, systemservice’s getTime method is called.
Line(54~56) : windowState is a value that the WebOSWindow QML component sends to the app. Whenever the windowState value changes, onWindowStateChanged is called. Its value is 1 when the app is in the background and 4 when the app is in the foreground, following the definition of Qt::WindowState. For details, see Qt::WindowState on Qt documentation.
Line(58~61) : Declare a PmLog object.
Note webOS OSE supports use of QtQuick module up to version 2.12, because webOS OSE supports Qt 5.12 LTS since 2.0.0 release. However, using lower version of QtQuick module can be helpful for keeping backward compatibility with other environments using a lower version of Qt. For details, refer to Qt documentation.
This file provides general information of the QML app.
Caution
If the README.md file is missing, a build error occurs.
Make sure the ‘Summary’ section is a single line. Even any whitespace at the line above the ‘Description’ section is considered a part of the summary and can cause the build to fail.
Sample README.md
Summary
-------
QML app sample
Description
-----------
QML app sample
How to Build on Linux
---------------------
## Dependencies
Below are the tools and libraries (and their minimum versions) required to build sample program:
* qmake
## Building
$ cd build-webos
$ source oe-init-build-env
$ bitbake com.example.app.qml
Copyright and License Information
=================================
Unless otherwise specified, all content, including all source code files and
documentation files in this repository are:
Copyright (c) 2020 LG Electronics, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
Step 2: Configure the QML App
This section describes how to prepare the configuration files required to build and test the QML app.
appinfo.json
Apps are required to have metadata before they can be packaged. This metadata is stored in a file called appinfo.json, which is used by the webOS device to identify the app, its icon, and other information that is needed to launch the app.
Line(8) : The icon to be shown on the Launchpad and App Bar. Make sure the icon file is available in the project root directory. You can use your own icon.png (80*80) file or attached icon.png.
Line(9) : Specify the group to which the external service’s method called by the app belongs.
Because systemservice’s getTime method belongs to “time.query” group, put “time.query” in this property.
When qml-runner launches QML app, qml-runner calls the method to register the app to SAM. To enable qml-runner to call this method, put “application.operation” group.
To check the group of each method, use ls-monitor command with “-i” option.
This file specifies the application name and the qmake template to be used for generating the project, as well as the source, header, and UI files included in the project.
After implementing and configuring the QML app, you must build the app.
Add the Recipe File
webOS OSE uses OpenEmbedded of Yocto Project to build its components. OpenEmbedded needs a recipe file that configures the build environment. For more details about the recipe, see Yocto Project Reference Manual.
You must move the recipe file into webOS OSE project directory.
Line(6) : A list of a package’s build dependencies. Add qtbase, qt-features-webos, qtdeclarative, and pmloglib.
Line(7) : A list of a package’s runtime dependencies (other packages) that must be installed in order for the built package to run correctly. Add qml-webos-bridge and qml-webos-framework.
Line(9) : Version of the component. For the webOS OSE component, this field is mandatory.
Line(10) : Revision version of the recipe. Each recipe requires a counter to track its modification history. Make sure that you increment the version when you edit the recipe, unless you only change the value of the WEBOS_VERSION field or comments.
Line(12) : Instruct OpenEmbedded that the component uses QMake for configuration, which is the preferred choice for webOS components.
Line(13) : Instruct OpenEmbedded to use the WEBOS_VERSION value as the component version number. If you develop your component on a local repository, this entry is required.
Line(14) : Inherit webos_app, because the component is an app.
Line(16) : ${webos_applicationsdir} indicates /usr/palm/applications. ${PN} is the package name, which is set to com.example.app.qml.
Configure the Local Source Directory
To build a component that is located on the local system, you must specify the directory information.
You must move the configuration file into webOS OSE project directory.
Line(2) : The local source directory. The syntax of the property is EXTERNALSRC:pn-<component>. For the value, input "<absolute path of the project directory>"
Line(3) : The local build directory. The syntax of the property is EXTERNALSRC_BUILD:pn-<component>. For the value, input "<absolute path of the project directory>/build/"
Line(4) : The appended revision version (PR) for building local source files. The syntax of the property is PR:append:pn-<component>. This property is optional.
Note We recommend that you add a trailing slash (/) at the end of all local directory paths, as in Line(2) and Line(3).
Build the App
To build the component on the OpenEmbedded environment, enter the following commands on the shell:
After building the app, you must verify its functionality.
Copy the IPK to the target.
When the build is successful, oe-related directories are created under the project root directory. These directories are linked to the directory where the build output is generated from the actual build-webos sub-directory.
Copy the IPK file to the target device using the scp command.
~/project/com.example.app.qml/oe-workdir/deploy-ipks/raspberrypi4_64$ scp com.example.app.qml_1.0.0-r0.local0_raspberrypi4_64.ipk root@<target IP address>:/media/internal/downloads/
Install the app on the target.
Connect to the target using the ssh command and install com.example.app.qml_1.0.0-r0.local0_raspberrypi4_64.ipk.
$ ssh root@<target IP address>
root@raspberrypi4-64:/sysroot/home/root# cd /media/internal/downloads/
root@raspberrypi4-64:/media/internal/downloads# opkg install com.example.app.qml_1.0.0-r0.local0_raspberrypi4_64.ipk
Installing com.example.app.qml (1.0.0) on root.
Configuring com.example.app.qml.
Discover the LS2 configuration files.
To make LS2 daemon scan the LS2 configuration files of the app, use the ls-control command as follows.
root@raspberrypi4-64:/media/internal/downloads# ls-control scan-services
telling hub to reload setting and rescan all directories
Note For the QML app, LS2 configuration files are generated during the build process. To run the app properly, you must make the system scan the newly generated configuration files.
Scan the app.
To make System and Application Manager (SAM) scan the app, restart SAM using the systemctl command. This step is required so that the app can be added to the app list, which in turn makes the app appear on the Launchpad.
root@raspberrypi4-64:/# systemctl restart sam
Note Rebooting the target after installing the app will have the same effect as running the ls-control and systemctl commands. However, using the commands allows you to continue testing without rebooting.
Run the QML app.
Drag the mouse cursor upward from the bottom of the screen (or swipe up from the bottom of the screen if you’re using a touch display).
Note On webOS OSE 1.x, press the Windows key.
Click the Launchpad icon.
Click the app icon to see the window titled “QML app” with the following page: