本页内容

C

首个在全新平台上的Qt Quick Ultralite应用程序

既然平台移植工作已经完成,现在是时候在移植版本的基础上运行一个Qt Quick Ultralite应用程序了。

创建一个包含动画和触摸输入的新 QML 应用程序,该应用程序将在整个移植指南中使用,具体使用以下三个文件:

CMakeLists.txt

cmake_minimum_required (VERSION 3.21.1)

project(minimal_porting VERSION 0.0.1 LANGUAGES C CXX ASM)
if (NOT TARGET Qul::Core)
    find_package(Qul)
endif()

mcu_minimal_porting.qmlproject

import QmlProject 1.3

Project {
  mainFile: "minimal_porting.qml"
}

minimal.qml

import QtQuick 2.15

Rectangle {
    Component.onCompleted: {
        console.log("Hello World")
      }

    color: "forestgreen"

    Rectangle {
        width: 80
        height: 80
        anchors.centerIn: parent

        SequentialAnimation on width {
            running: true
            loops: Animation.Infinite
            PropertyAnimation {
                to: width/2;
                duration: 1000;
                easing.type: Easing.InOutQuad
            }
            PropertyAnimation {
                to: width/4;
                duration: 1000;
                easing.type: Easing.InOutQuad
            }
        }
    }

    MouseArea {
      anchors.fill: parent
      onClicked: {
            if (parent.color == 'silver')
                parent.color = 'forestgreen';
            else
                parent.color = 'silver';
        }
    }

    Text {
        anchors.centerIn: parent
        font.pixelSize: 30
        text: "Qt for MCUs"
    }
}

建筑

以下步骤将帮助您配置环境,以便构建该示例。

QUL_ROOT 在下面的命令行示例中,QUL_TOOLS 会被视为已设置的环境变量。例如:

export QUL_ROOT=$HOME/Qt/QtMCUs/2.12.3
export QUL_TOOLS=$HOME/Qt/Tools/QtMCUs
set QUL_ROOT=C:\Qt\QtMCUs\2.12.3
set QUL_TOOLS=C:\Qt\Tools\QtMCUs
    1. 创建构建目录:
      mkdir build
      cd build
    2. 使用以下命令配置并构建示例:

      根据所使用的工具链,您需要将 `CMAKE_TOOLCHAIN_FILE ` 设置为 `$QUL_ROOT/lib/cmake/Qul/toolchain/armgcc.cmake`、`$QUL_ROOT/lib/cmake/Qul/toolchain/iar.cmake ` 或您自定义的文件(如果您创建了自己的文件)。

      QUL_TARGET_TOOLCHAIN_DIR 指定要使用的工具链的位置。

      要在 Windows 上使用nmake ,请运行位于“VC\Auxiliary\Build ”Visual Studio 目录中的vcvarsx86_amd64.bat Windows 批处理文件。或者,您也可以运行“x86_x64 Cross Tools Command Prompt for VS 2017”或您所用 Visual Studio 版本对应的等效工具。

      cmake .. -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=$QUL_ROOT/lib/cmake/Qul/toolchain/<YOUR_TOOLCHAIN>.cmake -DQUL_TARGET_TOOLCHAIN_DIR=/path/to/the/toolchain -DQUL_GENERATORS=$QUL_ROOT/lib/cmake/Qul/QulGenerators.cmake -DQUL_PLATFORM=<YOUR_PLATFORM>
      cmake --build .
      cmake .. -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=%QUL_ROOT%\lib\cmake\Qul\toolchain\<YOUR_TOOLCHAIN>.cmake -DQUL_TARGET_TOOLCHAIN_DIR=C:\path\to\the\toolchain -DQUL_GENERATORS=%QUL_ROOT%\lib\cmake\Qul\QulGenerators.cmake -DQUL_PLATFORM=<YOUR_PLATFORM>
      cmake --build .

      如果您已按照“创建烧录目标”部分中的说明为您的平台创建了烧录目标,请使用以下命令对示例进行烧录:

      cmake --build . --target flash_minimal_porting

      刷写成功后,您应从设备输出端口收到以下消息:

      Unable to allocate platform screen for a Screen item, so it will not be visible. Ensure all outputDevice names are correctly set.
      Hello World

      由于尚未实现图形功能,因此会出现此警告。

    您现已完成移植指南的第一阶段,并可提交当前状态。下一阶段将实现屏幕图形显示。

    在某些 Qt 许可证下可用。
    了解更多信息。