Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Probem in displaying response recieved from server

Hey

Is it possible to display the response received from server in new page?

For example:

Here is the SLOT called onGetReply, it displays whether the file uploaded to server or not. Yes for suceess and no for failure.

 

void Application:Smiley SurprisednGetReply()
{
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

    QString response;
    if (reply) {
        if (reply->error() == QNetworkReply::NoError) {
            const int available = reply->bytesAvailable();
            if (available > 0) {
                const QByteArray buffer(reply->readAll());
                response = QString::fromUtf8(buffer);
            }
        } else {
            response = tr("Error: %1 status: %2").arg(reply->errorString(), reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString());
            qDebug() << response;
        }

        reply->deleteLater();
    }

    if (response.trimmed().isEmpty()) {
        response = tr("Unable to retrieve post response");
    }

    emit complete(response);
}

Now how it display it in new page???

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Probem in displaying response recieved from server

you could connect to the complete signal in qml with a function, use createObject there to create a new page, set a property with the response and use navigationPane (or similar) to push it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Probem in displaying response recieved from server

Hey Thanks for the reply

You are trying to say the complete signal that i used in the above code i wil connect that signal in the qml file and passed it to the new page whrer i want to display the response??

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Probem in displaying response recieved from server

I have to do like this???


import bb.cascades 1.0
import bb.multimedia 1.0
import bb.cascades.multimedia 1.0

NavigationPane {
    
    id: navigational
Page {
    id: photoPage
    
    actions:
        [
            ActionItem
            {
                id: capture
                title: "Capture"
                ActionBar.placement: ActionBarPlacement.OnBar
                onTriggered:
                {
                    camera.capturePhoto();
                    
                }
                
            }
        ]

   content:  Container
   {
       
       
        Container {
            horizontalAlignment: HorizontalAlignment.Fill
            verticalAlignment: VerticalAlignment.Fill

            
            Camera {
                id: camera
                property bool photoBeingTaken
                attachedObjects:
                    [
                        CameraSettings
                        {
                            id: settings
                            
                        },
                        SystemSound
                        {
                            id: sound
                            sound: SystemSound.CameraShutterEvent
                            
                        }
                    ]
               
               onCreationCompleted:
               {
                   camera.open(CameraUnit.Rear);
               }


                onCameraOpened:
                {
                    if(photoBeingTaken==false)
                    {
                        photoBeingTaken=true ;
                        camera.startViewfinder();
                    }
                }
                onViewfinderStarted:
                {
                    photoBeingTaken=false
                    
                }
                
                onShutterFired:
                {
                    sound.play();    
                }
                
                onPhotoSaved:
                {
                    photoBomber.manipulatePhoto(fileName);
                    // Will set the filename of the latest captured bomber photo in the ImageButton property.
                    setting.lastFileName = fileName;
                    // Makes the ImageButton visible when a photo is captured.
                    setting.visible = false ;
                  
                    
                }
            }

//here i add the function

function complete(response)

{

var page= newPage.createObject();

navigational.push(page);

}

 


        }

    } // content Container

 

attachedObjects:

[

Component Defination

{

  id: newPage

source:"response.qml"

}

]

   
}// Page
}

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Probem in displaying response recieved from server

please keep your code to the required.
the function looks good, you are missing the connection to the signal though.
you could do it in onCreationCompleted.
Set the class that has the signal as a context property (for example as "app") and use app.complete.connect(complete) to create a connection between the signal and your slot (function).
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Probem in displaying response recieved from server

Sorry Simon i am not getting what are you saying?

In manipulatePhoto() methid i used the signal

connect(reply,SIGNAL(finished()),this,SLOT(onGetReply()));

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Probem in displaying response recieved from server

emit complete(response);

this emits the complete signal, with the response as a parameter.
connect to this signal in your qml to receive it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Probem in displaying response recieved from server

So the way i used above by creating the function complete(response) .

I hvae to add  that function in onCreationCompleted??

Forums Advisor I
Posts: 501
Registered: ‎03-01-2013
My Device: BlackBerry Z10

Re: Probem in displaying response recieved from server

Hey Simon got it

I have added it in onCreationCompleted

 

 onCreationCompleted:
               {
                   camera.open(CameraUnit.Rear);
                    photoBomber.complete.connect(complete(response));
                }

but i am not getting any response? And if the response displays, then it displays on the camera screen or the new Screen?

I want to display it on a new screen?

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Probem in displaying response recieved from server

you don't have to write out the parameter in qml, so change
photoBomber.complete.connect(complete(response));
to
photoBomber.complete.connect(complete);

i would suggest that you just use a console.log in the complete function to see if everything arrives as planned.

then you have to extend your code to give the new page the text:
var page= newPage.createObject();
page.response = response; //create a string property named response on the newPage component.
navigational.push(page);
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter