一直想动手试试qml,正好公司有个企业app是苹果的,我穷屌丝,买不起,后台我作的,我知道接口,就来个android的,qml之前只是看过,没有动手作东西。这是个练手的机会。html
先来几幅图片看看效果android
这是在个人ZTE红牛手机上运行的效果,android4.3。ios
这个小的app程序使用qml和js,文件操做使用了不多的C++来完成。网络
qml相似与html语言,在写界面时,其能够直白的来描述界面元素,非常方便。js的灵活性是业务逻辑写起来很顺手。app
在这个过程当中,我第一次写这个,不灵活,原本为了代码的可维护行,我想将js代码独立出来,但是发现这个有点麻烦,js须要操做界面元素,而后我只能独立出来逻辑,而后用js回调函数来实现。好比网络操做:函数
.pragma library function post(url_, data_, root, fun_, fun_1) { var xml_http_request = new XMLHttpRequest(); xml_http_request.onreadystatechange = function() { if (xml_http_request.readyState === 4 && xml_http_request.status === 200) { timer.stop() fun_(xml_http_request.responseText); } } xml_http_request.open("POST", url_, true); xml_http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //xml_http_request.timeout = 3000 //xml_http_request.ontimeout = fun_1 var timer = Qt.createQmlObject("import QtQuick 2.3; Timer {interval: 10000; repeat: false; running: true;}",root,"MyTimer"); timer.triggered.connect(function(){ console.log("close") xml_http_request.abort(); fun_1(); }); xml_http_request.send(data_); }
不过这个体验很好,qml+js。post
qml定制控件很方便,好比上图中的按钮和相似与ios上的选择的那个(day or hour)都是定制的,还有提示网络操做正在进行的,很简单就实现了想要的效果。
ui