1
votes
  1. Am using Json web service to get response
  2. When i press a button i have to push to new page when respone is success else have to show a toast -- already registerd
  3. I will get response either "Email id already registered" or "Registered success"
  4. When i get Registered Suceess only i have to push new page

Please help...


CPP FILE

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    
1
second.qml should be a Page, can u paste that qml. I guess ur getting error at this code execution Page *new_Page = qml->createRootObject<Page>();Manoj K
Please check the qml file.. am added the code above.. Please help to solve this issue.. am new to blackberry..Rajesh Loganathan
main.qml is not a navigation pane, u cannot push a page to a simple container. also paste second.qml i will try to frame for uManoj K
Get my full app source here.. you will get some idea.. github.com/BlackberryCascades/BB-10-Cascades/tree/master/…Rajesh Loganathan
1. Am using Json web service to get response 2. When i press a button i have to push to new page when respone is success else have to show a toast -- already registerd 3. I will get response either "Email id already registered" or "Registered success" 4. When i get Registered Suceess only i have to push new pageRajesh Loganathan

1 Answers

2
votes

Try this:

In your main.qml name a objectname for navigationpane like:

NavigationPane {
id: navigation
objectName: "mynavigation"

In your applicationui.cpp constructor change this lines:

 m_root = qml->createRootObject<AbstractPane>();

    m_pane = m_root->findChild<NavigationPane*>("mynavigation");

change these lines too after constructing second.qml:

   QmlDocument *qml = QmlDocument::create("asset:///second.qml").parent(this);
               qml->setContextProperty("app", this);  


Page *new_Page = qml->createRootObject<Page>();  
m_pane->push(new_Page);

CPP FILE:

    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 = m_root->findChild<NavigationPane*>("mynavigation"); //  changed
        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);
                         qml->setContextProperty("app", this);   // changed
                       Page *new_Page = qml->createRootObject<Page>();
                       m_pane->push(new_Page);
                              **?????????????????????????????**

            }