qml 中怎么qml 获取当前时间系统时间

QML中怎么获取listview点击的i_百度知道QML(182)
移动开发(262)
Ubuntu OS(147)
手机开发(124)
Item是QML语言中最基本的元素。有时为了方便,我们可以列出它里面的所有的属性,信号及方法。我们可以通过这个方法来修改我们的属性等。在QML语言中,所有的可视的控件都是继承于Item的。
下面我们来通过一个例子来展示如何这么做。我们可以设计一个简单的QML应用如下:
import QtQuick 2.0
ponents 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: &properties.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(100)
height: units.gu(75)
title: i18n.tr(&properties&)
Rectangle {
x: 0; y: 0
width: 100; height: 100
color: &blue&
Component.onCompleted: {
var keys = Object.keys(rect);
for(var i = 0; i & keys. i++) {
var key = keys[i];
// prints all properties, signals, functions from object
console.log(key + ' : ' + rect[key]);
if (key === &x&) {
rect[key] = 100;
这里rect最初的坐标为(0,0)。在Component.onCompleted中,我们遍历所有的属性,信号及方法。我们把x的值修改为100。最后运行的结果如下:
在Qt Creator的“Application Output”窗口中,我们可以看到:
qml: objectName :
qml: parent : Page11_QMLTYPE_42(0x1a55340)
qml: data : [object Object]
qml: resources : [object Object]
qml: children : [object Object]
qml: x : 0
qml: y : 0
qml: z : 0
qml: width : 100
qml: height : 100
qml: opacity : 1
qml: enabled : true
qml: visible : true
qml: visibleChildren : [object Object]
qml: states : [object Object]
qml: transitions : [object Object]
qml: state :
qml: childrenRect : QRectF(0, 0, 0, 0)
qml: anchors : QQuickAnchors(0x1a49840)
qml: left : QVariant(QQuickAnchorLine)
qml: right : QVariant(QQuickAnchorLine)
qml: horizontalCenter : QVariant(QQuickAnchorLine)
qml: top : QVariant(QQuickAnchorLine)
qml: bottom : QVariant(QQuickAnchorLine)
qml: verticalCenter : QVariant(QQuickAnchorLine)
qml: baseline : QVariant(QQuickAnchorLine)
qml: baselineOffset : 0
qml: clip : false
qml: focus : false
qml: activeFocus : false
qml: activeFocusOnTab : false
qml: rotation : 0
qml: scale : 1
qml: transformOrigin : 4
qml: transformOriginPoint : QPointF(50, 50)
qml: transform : [object Object]
qml: smooth : true
qml: antialiasing : false
qml: implicitWidth : 0
qml: implicitHeight : 0
qml: layer : QQuickItemLayer(0x1b90010)
qml: color : #0000ff
qml: gradient : null
qml: border : QQuickPen(0x1b8bd50)
qml: radius : 0
qml: objectNameChanged : function() { [code] }
qml: childrenRectChanged : function() { [code] }
qml: baselineOffsetChanged : function() { [code] }
qml: stateChanged : function() { [code] }
qml: focusChanged : function() { [code] }
qml: activeFocusChanged : function() { [code] }
qml: activeFocusOnTabChanged : function() { [code] }
qml: parentChanged : function() { [code] }
qml: transformOriginChanged : function() { [code] }
qml: smoothChanged : function() { [code] }
qml: antialiasingChanged : function() { [code] }
qml: clipChanged : function() { [code] }
qml: windowChanged : function() { [code] }
qml: childrenChanged : function() { [code] }
qml: opacityChanged : function() { [code] }
qml: enabledChanged : function() { [code] }
qml: visibleChanged : function() { [code] }
qml: visibleChildrenChanged : function() { [code] }
qml: rotationChanged : function() { [code] }
qml: scaleChanged : function() { [code] }
qml: xChanged : function() { [code] }
qml: yChanged : function() { [code] }
qml: widthChanged : function() { [code] }
qml: heightChanged : function() { [code] }
qml: zChanged : function() { [code] }
qml: implicitWidthChanged : function() { [code] }
qml: implicitHeightChanged : function() { [code] }
qml: update : function() { [code] }
qml: grabToImage : function() { [code] }
qml: grabToImage : function() { [code] }
qml: contains : function() { [code] }
qml: mapFromItem : function() { [code] }
qml: mapToItem : function() { [code] }
qml: forceActiveFocus : function() { [code] }
qml: forceActiveFocus : function() { [code] }
qml: nextItemInFocusChain : function() { [code] }
qml: nextItemInFocusChain : function() { [code] }
qml: childAt : function() { [code] }
qml: colorChanged : function() { [code] }
qml: radiusChanged : function() { [code] }
这些都是我们可以用到的。通过这个方法,我们可以全面地了解rect的所有属性。特别适用于一些动态生产的控件。我们可以用来修改它们的一些属性等。
项目的源码在:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:219893次
积分:5039
积分:5039
排名:第3838名
原创:283篇
评论:221条
(2)(3)(9)(6)(15)(8)(26)(4)(8)(1)(13)(6)(17)(18)(16)(23)(30)(16)(7)(2)(4)(8)(8)(11)(12)(18)QML如何与C++配合实使用_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
QML如何与C++配合实使用
上传于||文档简介
&&介​绍​Q​M​L​中​调​用​C​+​+​,​C​+​+​中​调​用​Q​M​L
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩11页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢评论- 269&
&&&&&&&&&&&
依赖ajax.js类库,以下代码很简单的实现了获取天气json数据并展示的任务
【TestAjax.qml】
1 import QtQuick 2.0
2 import "ajax.js" as Ajax
6 测试用ajax 获取 json 数据
7 更复杂的ajax调用请查看 qml/network/ 相关示例
width: 600
height: 400
spacing: 10
columns: 2
Text {text: 'city:'}
Text {id: text:' '}
Text {text: 'date:'}
Text {id: text:' '}
Text {text: 'temp:'}
Text {id:temp1; text:' '}
Component.onCompleted: {
// 中国天气网实况天气接口(可用)
Ajax.get(".cn/data/sk/.html",
function(result, json){
city.text = json.weatherinfo.
date.text = json.weatherinfo.
temp1.text = json.weatherinfo.
// 中华万年历的当天及预告天气接口(可用)
Ajax.get("/weather_mini?city=%E5%8C%97%E4%BA%AC",
function(result, json){
city.text = json.data.
date.text = json.data.forecast[0].
temp1.text = json.data.
// 中国天气网当天及预告天气接口(接口挂了)
Ajax.get(".cn/data/.html",
function(result, json){
city.text = json.weatherinfo.
date.text = json.weatherinfo.date_y;
temp1.text = json.weatherinfo.temp1;
【ajax.js】
2 function get(url, success, failure)
var xhr = new XMLHttpR
xhr.open("GET", url);
xhr.onreadystatechange = function() {
handleResponse(xhr, success, failure);
xhr.send();
12 // POST
13 function post(url, arg, success, failure)
var xhr = new XMLHttpR
xhr.open("POST", url);
xhr.setRequestHeader("Content-Length", arg.length);
xhr.setRequestHeader("Content-Type", "application/x-www-form-");
//用POST的时候一定要有这句
xhr.onreadystatechange = function() {
handleResponse(xhr, success, failure);
xhr.send(arg);
27 // 处理返回值
28 function handleResponse(xhr, success, failure){
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status ==
if (success != null && success != undefined)
var result = xhr.responseT
success(result, JSON.parse(result));
}catch(e){
success(result, {});
if (failure != null && failure != undefined)
failure(xhr.responseText, xhr.status);
阅读(...) 评论()

参考资料

 

随机推荐