BlackBerry Java to BlackBerry 10 Cascades Porting Series – Part 3: Networking

Native SDK Development

Networking in BlackBerry 7 OS was based on the paradigm, where you would specify the protocol and transport in the connection string (“;deviceside=true”), and get back a Connection object of a certain type (HttpConnection, for example).

Networking in BlackBerry 10 is done through the QNetwork module. You no longer need to worry about transport selection. Your typical HTTP communication can be handled through QNetworkAccessManager. It provides methods such as get() and post(), which take a QNetworkRequest and then asynchronously return a QNetworkReply.

For example:

QUrl *url = new QUrl("");

    QNetworkAccessManager *manager = new QNetworkAccessManager(this);

    connect(manager, SIGNAL(finished(QNetworkReply*)),
    		this, SLOT(replyFinished(QNetworkReply*)));


And then in your replyFinished slot:

void App::replyFinished(QNetworkReply* reply) {
	qDebug() <readAll();

	// Call deleteLater to make sure the reply gets cleaned up

You can also do TCP with QTCPSocket and QTCPServer, UDP with UDPSocket , and FTP with QFtp.

And of course, lower level libraries such as cURL are available if you should require them.

Join the conversation

Show comments Hide comments
+ -