Testing QtQuick on Raspberry Pi

04/09/2017 - 18:08
No votes yet

So now you have a shiny new Qt build on your Raspberry Pi. Now what ? Testing!

Start your favorite editor (nano, vi, emacs, editor-of-choice) and paste the following code into it and then save it as main.qml

Example QtQuick code

import QtQuick 2.8
import QtQuick.Window 2.2
import QtQuick.Controls 2.0

ApplicationWindow {
    visible: true
    width: 1920
    height: 1080
    visibility: Window.FullScreen
    title: qsTr("Hello World")

    Page {
        anchors.fill: parent
        focus: true
        Rectangle {
            color: "#e8e8e8"
            anchors.centerIn: parent
            width: 800
            height: 600
            Image {
                id: debianLogo
                fillMode: Image.PreserveAspectFit
                anchors.centerIn: parent
                source: "/usr/share/pixmaps/debian-logo.png"
            }
            Label {
                anchors.top: debianLogo.bottom
                text: "Hello World From QtQuick!"
            }
        }
        Keys.onReleased: {
            if (event.key === Qt.Key_Escape) {
                Qt.quit()
            }
        }
    }
}

Show the QtQuick app

Next run:

/opt/Qt5.8/bin/qmlscene main.qml

You should now see grey box in the middle of the screen with the Debian logo in the center. Press ESC to exit the test application.

Keywords: 
Qt
QtQuick
Raspberry Pi