- 我正在使用 Json Web 服务来获得响应
- 当我按下按钮时,我必须在响应成功时推送到新页面,否则必须显示敬酒 - 已经注册
- 我会收到回复“电子邮件 ID 已注册”或“注册成功”
- 当我获得注册成功时,我只需要推送新页面
请帮忙...
文件
ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
QObject(app)
, m_succeeded(false)
, m_active(false)
{
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("app", this);
//qml->setContextProperty("second", m_pane);
m_root = qml->createRootObject<AbstractPane>();
m_pane = new NavigationPane;
app->setScene(m_root);
}
void ApplicationUI::sendRequest()
{
if (m_active)
return;
m_active = true;
emit activeChanged();
m_succeeded = false;
QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
QNetworkRequest request(m_urllink);
QNetworkReply* reply = networkAccessManager->get(request);
bool ok = connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
void ApplicationUI::onFinished()
{
m_succeeded = true;
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200)
{
JsonDataAccess jda;
QVariantMap map = jda.loadFromBuffer(reply->readAll()).toMap();
QVariantList addresses = map["RegistrationResult"].toList();
qDebug() <<"Full Result is = "<<map["RegistrationResult"].toString();
QString m_temperature;
QString result;
result = map["RegistrationResult"].toString();
m_temperature=result.section(':', 0, 0);
m_urlResult = result;
emit urlResultChanged();
qDebug()<<m_urlResult;
qDebug()<<"\n\n\n";
if(result == "EMAIL ID ALREADY EXISTS")
{
qDebug() << " New Registration Result is " <<m_temperature;
qDebug() <<map["RegistrationResult"].toString();
}
else if(result != "EMAIL ID ALREADY EXISTS")
{
QString empid;
QString empid_no;
QString::SectionFlag flag = QString::SectionSkipEmpty;
result = map["RegistrationResult"].toString();
//empid=m_temperature.section(':', 1, 1);
empid_no = map["RegistrationResult"].toString();;
empid_no=empid_no.section(':', 2, 2);
qDebug()<<"Emd ID = "<<empid_no;
qDebug()<<"Company ID"<<result.section(':', 4, 4);
QmlDocument *qml = QmlDocument::create("asset:///second.qml").parent(this);
Page *new_Page = qml->createRootObject<Page>();
m_pane->push(new_Page);
**?????????????????????????????**
}
main.qml
import bb.cascades 1.2
import bb.system 1.2
import "controls"
NavigationPane {
id: navigation
Page {
titleBar: TitleBar {
id: mainPage
title: "ERS"
}
Container
{
id: mainContainer
Button {
id: next
text: "NEXT"
onClicked: {
app.clickedButton(cnametxt.text,hrtxt.text,emailtxt.text,addresstxt.text,phnotxt.text,pwdtxt.text,vhclnotxt.text,vhclmodeltxt.text,urltxt.text);
app.sendRequest();
mainContainer.urlresult(); // to push page am using javascript
}
}
Label {
id: urlresulttxt
text: app.urlResult
visible: app.urlResult=="EMAIL ID ALREADY EXISTS"
textStyle.color: Color.Red
}
function urlresult()
{
if (app.urlResult != "EMAIL ID ALREADY EXISTS" && app.urlResult != null )
{
toast.body = "Success"
toast.show();
var page = nextPage.createObject();
navigation.push(page);
}
else if (app.urlResult == "EMAIL ID ALREADY EXISTS") {
toast.body = "EMAIL ID ALREADY EXISTS"
toast.show();
}
}
attachedObjects: [
ComponentDefinition {
id: nextPage
source: "second.qml"
},
SystemToast {
id: toast
}
]
} //container
} // page
} // nav