Ankita Singh
Ankita Singh

Reputation: 1

BB Slot not firing for Http Connection

I am very new to blackberry and working with cascades. I've implemented a simple http connection (HTTP POST).

The response is problematic, sometimes I am the response is shown in a toast, and sometimes it simply doesn't show anything.

Here is the code :

void ApplicationUI::work(QString clgId){
    QNetworkAccessManager connection;
    QUrl url("http://abc.co.in/test/test.php");
    //url.addQueryItem("parameter", "2");
    //QNetworkRequest request(url);

    QByteArray data;
    data.append("test=1");
    QNetworkReply *reply = connection.post(request, data);
    connect(reply, SIGNAL(finished()), SLOT(postFinished()));
    showToast("OK");/*If I comment this line. The postFinished() is not called*/
}

void ApplicationUI::postFinished(void){
    showToast("PostFinished");
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    if (reply->error() == QNetworkReply::NoError){
        // No error
        QString result = reply->readAll();
        showToast(result);
    }
    else{
        // error occurred
        int errorCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
        qDebug() << errorCode << endl << reply->errorString();
        showToast(reply->errorString());
    }


    reply->deleteLater();
}

void ApplicationUI::showToast(QString text) {

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

I am in a fix about what the problem is, please help.

Upvotes: 0

Views: 49

Answers (1)

Oliver Kranz
Oliver Kranz

Reputation: 3841

I would recommend having a look at the BlackBerry 10 Networking documentation.

Networking documentation

There is also a sample project showing how to use HTTP post and HTTP get to communicate with a server.

github sample project

Upvotes: 1

Related Questions