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
Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Working with server

Much easier is to identify problem, when i (we) can see it. Please, give me (us) part of code where is occurred the error



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: Working with server

Hello Benecore,

 

    The program is executing without any error . I have toast for displaying reply . But in that it's showng 'invalid access' .

 

 

Here is that code --

// Default empty project template
#include "ServerDemo.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>


#include <bb/system/SystemToast>

using namespace bb::cascades;

ServerDemo::ServerDemo(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);


    qml->setContextProperty("_app",this);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
    app->setScene(root);

}


void ServerDemo::doPost()
{
	QNetworkAccessManager connection;


	QUrl url("my url");

	url.addQueryItem("parameter", "14");

	QNetworkRequest request(url);
	showToast("2");
	QByteArray postParameters;

	    postParameters += "paremater1=";
	    postParameters += "value1";
	    postParameters += "&";
	    postParameters += "paremater2=";
	    postParameters += "value2";

	    QNetworkReply *reply = connection.post(request, postParameters);
	    connect(reply, SIGNAL(finished()), SLOT(postFinished()));

}


void ServerDemo::postFinished(){
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    if (reply->error() == QNetworkReply::NoError){
        // No error
        QString result = reply->readAll();


        showToast(result);
    }
    else{
        // error occured
        int errorCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
        qDebug() << errorCode << endl << reply->errorString();
    }
    

    reply->deleteLater();
}

void ServerDemo::showToast(QString text) {

	bb::system::SystemToast toast;
	toast.setBody(text);
	toast.setPosition(bb::system::SystemUiPosition::BottomCenter);
	toast.exec();


}

 

 

Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Working with server

[ Edited ]

And on which line you get Invalid access? Can you post the whole error message,  cause i don't see any error in the code :smileywink:



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: Working with server

void ServerDemo::postFinished(){
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    if (reply->error() == QNetworkReply::NoError){
        // No error
        QString result = reply->readAll();


        showToast(result);   // Line 1
    }
    else{
        // error occured
        int errorCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
        qDebug() << errorCode << endl << reply->errorString();
    }
    

    reply->deleteLater();
}

 I said I am not getting error . I have shown the reply in toast ( commented as line 1) . So its showing 'invalid access' in toast.

Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Working with server

:Oops: Aha, sorry I've only just got up :Sleep1:

 

So the string of result

QString result = reply->readAll();

is invalid access, or? If you debug the output what output you get?

 

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: Working with server

:smileyhappy: Its okay.... yes the string of result showing ' invalid access '  in toast.  

Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Working with server

So topic is solved :smileywink: Great



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: Working with server

I didnt get your point. I am not getting why is this happening? 

Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Working with server

Your code is ok, i think. Invalid access is server response so you probably send bad request to server.



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: Working with server

You are saying code is ok then what should I do to resolve this problem 

what do you mean by bad request?