在给定的代码中,我使用了一个标签和一个按钮。我希望当我单击按钮时必须发送一个请求,该请求从给定链接获取 Json 并在标签上打印。但是对于这段代码,我只是在成功后在标签内打印“OK”
我面临的问题是我没有进入 if 语句。实际上在按钮单击时没有任何反应。我知道 QT 中有我可以使用的网络管理器,但在我的情况下,我想在 QML 中解析
// Default empty project template
import bb.cascades 1.0
// creates one page with a label
Page {
Container {
layout: StackLayout {}
Label {
id: msgLabel
text: qsTr("Hello World")
textStyle.base: SystemDefaults.TextStyles.BigText
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
}
Button {
id: requestXML
objectName: "requestXML"
onClicked: {
var doc = new XMLHttpRequest();
doc.onreadystatechange = function() {
if (doc.readyState == 4) {
msgLabel.text="OK"
// pass “doc.responseText” to C++ for Parsing
}
}
doc.open("GET", "http://www.example.com/sample.json", true);
doc.send();
}
}
}
}
在我的 .pro 文件中,我已经声明
CONFIG += qt warn_on cascades10
QT += network
CONFIG += debug
CONFIG += console
LIBS += -lbbdata
QT +=script
QT +=scripttools
我哪里错了?或者我必须声明一些别的东西