在QML的UbuntuApplication Context Property

185 篇文章 7 订阅
159 篇文章 2 订阅

我们可以在Ubuntu SDK的文档中可以看到UbuntuApplication API。但是我们看不到它的具体的用法。在这篇文章中,我们来通过如下的方法来查看一下该如何使用该API。


import QtQuick 2.0
import Ubuntu.Components 1.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: "ubuntuapplication.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)

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

        Text {
            text: UbuntuApplication.applicationName
        }

        Component.onCompleted: {
            var keys = Object.keys(UbuntuApplication);
            for(var i = 0; i < keys.length; i++) {
                var key = keys[i];
                // prints all properties, signals, functions from object
                console.log(key + ' : ' + UbuntuApplication[key]);

                if (key === "x") {
                    rect[key] = 100;
                }
            }
        }
    }
}


运行我们的应用:




Starting /usr/lib/x86_64-linux-gnu/qt5/bin/qmlscene...
qml: objectName : 
qml: applicationName : ubuntuapplication.liu-xiao-guo
qml: objectNameChanged : function() { [code] }
qml: applicationNameChanged : function() { [code] }


从上面的输出可以看出来,UbuntuApplication目前没有多少的属性让我们来使用。其中的applicationName,我们也可以使用Qt.application.name来的到。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值