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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
Developer
Posts: 55
Registered: ‎09-09-2013
My Device: Dev Alpha C
My Carrier: Etisalat
Accepted Solution

Weather sample code using QNetworkRequest

[ Edited ]

I'm trying to get Weather temperature using QNetworkRequest as follow:

 

===================================

QNetworkAccessManager qNam;
QNetworkReply *temperReply;

 

void Class::getWeatherTemperature(QString lat, QString lon){


temperReply = qNam.get(QNetworkRequest(QUrl("api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+lon)));

 

connect(temperReply, SIGNAL(finished()), this, SLOT(onFinishedTemperature()));

 

}

 

void Class:: onFinishedTemperature(){

QNetworkReply *weatherReply = dynamic_cast<QNetworkReply*>(sender());

qDebug()  << weatherReply->errorString() << weatherReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

 

//other code

}

 

==================================

 

but it does not work .. i got errorString:  Protocol "" is unknown 

 

 

 

is there weather sample code using QNetworkRequest? 

 

Be like Dan Brown, get the dimensions of every place you visit!
MeasureMe on App World
Developer
Posts: 237
Registered: ‎05-21-2012
My Device: BlackBerry RED Z10
My Carrier: WiFi

Re: Weather sample code using QNetworkRequest

try check if it connected the signal and slot 

 

bool connected = connect(temperReply, SIGNAL(finished()), this, SLOT(onFinishedTemperature()));

 

qDebug() << "CONNECTED: " << connected;

Developer
Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: Weather sample code using QNetworkRequest

Your URL needs to include the server & domain information, and also the protocol prefix:

 

QUrl qurl("http://server.domain.com/api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+lon);

 

temperReply = qNam.get(QNetworkRequest(qurl));

 

Developer
Posts: 1,750
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV, DTEK
My Carrier: Telekom.de, O2, Vodafone

Re: Weather sample code using QNetworkRequest


nemory wrote:

try check if it connected the signal and slot 

 

bool connected = connect(temperReply, SIGNAL(finished()), this, SLOT(onFinishedTemperature()));

 

qDebug() << "CONNECTED: " << connected;


better this way:

 

bool connected = ......

Q_ASSERT(connected);

 

Q_ASSERT will stop the app - but only in DEBUG mode.

it's more safe this way - sometimes there are so many debug messages you perhaps overlooking it

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
QtChampion
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS, W10)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 55
Registered: ‎09-09-2013
My Device: Dev Alpha C
My Carrier: Etisalat

Re: Weather sample code using QNetworkRequest

it is connected and i added the server info but still receiving "Unknown Error" and empty reply (error code 0)

Be like Dan Brown, get the dimensions of every place you visit!
MeasureMe on App World
Developer
Posts: 55
Registered: ‎09-09-2013
My Device: Dev Alpha C
My Carrier: Etisalat

Re: Weather sample code using QNetworkRequest

[ Edited ]

finally worked by calling "connect" before "get" and passing the network access manager (not the reply) object to the connect function as in this link:

 

https://developer.blackberry.com/native/documentation/cascades/device_comm/networking/index.html

 

Be like Dan Brown, get the dimensions of every place you visit!
MeasureMe on App World