如何优化在Ubuntu手机中的QML应用

在我们写QML应用时,我们如何来优化我们的应用呢?在Ubuntu平台的API中,有一个API叫做"PerformanceOverlay".就像它的名字所说的,它是一个overlay.它可以用来显示一个应用启动或运行时所需要的时间及CPU的使用情况.我们下面来用一个小的应用来测试一下:


import QtQuick 2.0
import Ubuntu.Components 1.1
import Ubuntu.PerformanceMetrics 0.1

/*!
    \brief MainView with a Label and Button elements.
*/

MainView {
    // objectName for functional testing purposes (autopilot-qt5)
    objectName: "mainView"

    // Note! applicationName needs to match the "name" field of the click manifest
    applicationName: "performanceoverlay.liu-xiao-guo"

    /*
     This property enables the application to change orientation
     when the device is rotated. The default is false.
    */
    //automaticOrientation: true

    // Removes the old toolbar and enables new features of the new header.
    useDeprecatedToolbar: false

    width: units.gu(60)
    height: units.gu(85)

    PerformanceOverlay {
        active: true
    }

    Page {
        title: i18n.tr("PerformanceOverlay")

        Column {
            spacing: units.gu(1)
            anchors {
                margins: units.gu(2)
                fill: parent
            }

            Label {
                id: label
                objectName: "label"

                text: i18n.tr("Hello..")
            }

            Button {
                objectName: "button"
                width: parent.width

                text: i18n.tr("Tap me!")

                onClicked: {
                    label.text = i18n.tr("..world!")
                }
            }
        }
    }
}


当我们运行我们的应用时,在我们的应用的上面显示一个overlay.它是一个漂浮的窗口,我们可以用我们的手指来拖动它,以显示更好的效果.



在上面的图中,我们可以看出CPU的使用率,同时,当我们点击"Tap me"按钮时所显示需要的时间.如果显示为红色,它意味着我们需要做以下事情来优化我们的应用.

所有的源码在https://github.com/liu-xiao-guo/performanceoverlay




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值