Start of development for Sailfish OS

  • Tutorial
Sailfish OS is a mobile platform based on the Linux kernel. You can read about it on the official website or in one of the platform reviews on the network. For example, one of them was published on GeekTimes . In this article, I would like to touch upon the process of developing applications for Sailfish OS, talk about how to start programming for this platform, and also share some features of development.



To write applications for the Sailfish OS platform, C ++ and Qt libraries are used, as well as QML to describe the graphical interface of applications. Therefore, if you already have experience writing applications using Qt and QML, development for Sailfish OS will not be difficult for you. In addition, Sailfish OS allows you to develop native Python applications. However, this topic is beyond the scope of this article and will not be described in it (more about this can be read, for example, here ).

As for other mobile platforms, development for Sailfish OS is carried out using the SDK provided by the creators of the platform. SailfishOS SDK includes:
  • QtCreator - IDE, in which actually it is proposed to lead the entire development process.
  • Mer Build Engine, which is necessary for building applications.
  • Sailfish OS emulator.
  • API examples, manuals, and documentation.


The Mer Build Engine and platform emulator come in the form of virtual machine images for VirtualBox. However, VirtualBox itself is not part of the SailfishOS SDK. Therefore, before installing the SDK directly, you must first install VirtualBox version no lower than 4.1.18. In addition, when working on Windows, before installing the SDK, you also need to install the Microsoft Visual C ++ 2010 redistributable (x86) Windows package.

SailfishOS SDK itself is available for Linux, Windows and Max OS X, it can be downloaded here. The SDK comes as a graphical installer, so installing the SDK does not cause any difficulties. However, during installation you will be asked an alternative path for projects. This parameter is necessary for the virtual machine with the Mer Build Engine to have access to the source codes of your project. By default, this is your home directory. Subsequently, this parameter can be changed in the settings of Qt Creator.

After installing the SDK, you are fully prepared to develop applications for the Sailfish OS platform.

Creating Hello World! applications also does not cause any difficulties. Just run Qt Creator, click on the "New Project" button on the main screen (or via the File -> Create File or Project ... menu) and configure the project:
  1. Select SailfishOS Qt Quick Application as the application type:

  2. Specify the name and directory in which to save the project data (remember that the project should only be saved in your home directory or in the alternative path for the projects specified during installation or in the Qt Creator settings, since Mer Build Engine must have access to build the project him):

  3. We select the necessary kits that will be used to build the application.

    In total, as can be seen from the screenshot above, two sets are available:
    • MerSDK-SailfishOS-armv7hl - for devices based on the ARM architecture (for example, a Jolla smartphone),
    • MerSDK-SailfishOS-i486 - for devices based on Intel architecture.

    It is also worth noting here that the emulator only works with the i486 kit. Therefore, if you plan to test your application in the emulator, you need to choose the second set at this step.
  4. Specify additional information about the project:

  5. And that's it, the SDK generated a Hello World project for us.


An automatically generated project is a bit more complicated than the standard one-page Hello World. This allows you to immediately reveal some of the features of Sailfish OS. The standard page displays a standard greeting. However, if you swipe down on this screen (standard control for this platform), a menu will appear at the top allowing you to go to the second page of the application, where the list of elements is located.

The following are screenshots of the Hello World application:


Now let's take a look at the code. Everything is standard here for QML applications and therefore is familiar to anyone who has ever written applications using this language. A single .cpp file describes which .qml should be displayed when the application starts. In our case, this is HelloWorld.qml . In addition, the project contains 2 pages, as well as Cover Page, which determines the type of application on the Sailfish OS home screen, which displays thumbnails of all running applications and allows you to switch between them or close them.

HelloWorld.qmldescribes the main application window. It indicates the application’s start page and Cover Page, as well as additional application settings (in our case, these are the allowed screen orientations and the default screen orientation):
ApplicationWindow
{
    initialPage: Component { FirstPage { } }
    cover: Qt.resolvedUrl("cover/CoverPage.qml")
    allowedOrientations: Orientation.All
    _defaultPageOrientations: Orientation.All
}


FirstPage.qml describes the start page of the application. Everything is standard here for QML applications, but there is some Sailfish OS feature that you should pay attention to:
//...
SilicaFlickable {
    anchors.fill: parent
    PullDownMenu {
        MenuItem {
            text: qsTr("Показать вторую страницу")
            onClicked: pageStack.push(Qt.resolvedUrl("SecondPage.qml"))
        }
    }
//...

Here we use the SilicaFlickable element , which, firstly, allows you to make the content inside the element scrollable, if it does not completely fit into the element. And secondly, it allows you to use PullDownMenu - the very application menu that is opened by swiping down.

In addition, I would also like to pay attention to CoverPage.qml , which describes the Cover Page application. It contains the following element:
CoverActionList {
    id: coverAction
    CoverAction {
        iconSource: "image://theme/icon-cover-next"
    }
    CoverAction {
        iconSource: "image://theme/icon-cover-pause"
    }
}


This element allows, in addition to displaying information, also provide the user with the ability to control the application directly from its thumbnail on the home screen.

To start the application in the emulator, you need to select the i486 kit in the side menu, the desired build type (release or debugging) and the Deploy as RPM Package installation method :


After that, just click on the green arrow in the side menu. This action will build the application, launch the emulator, install and run your application on the emulator.

In addition, you can simply start the emulator by clicking on the button in the side menu. This will allow you to simply explore Sailfish OS without having a device on this platform.

That's all, in the future I will try to describe in more detail some features of development for the Sailfish OS platform.

Article author: Denis Laure

UPD: Thank you very much @kirikch for comments and comments, they were taken into account in the updated text of the article.

Also popular now: