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
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10
My Carrier: Aircel

How to track HTTP error of webview in cascades

Hi All,

 

I am using webview in my qml to load the images, but the problem is this I am unable to track the HTTP error inside the webview. So please provide any way to track these error.

Here is the code for webview which i am using:

 

WebView {
                                        id: webViewImage
                                        url: ListItemData.thumbnailPath
                                        settings.javaScriptEnabled: true
                                        onLoadingChanged: {
                                            if (loadRequest.status == WebLoadStatus.Started) {
                                                showLoader();
                                            } else if (loadRequest.status == WebLoadStatus.Succeeded) {
                                                hideLoader();
                                                defaultImage.visible = false;
                                            } else if (loadRequest.status == WebLoadStatus.Failed) {
                                                hideLoader();
                                                defaultImage.visible = true;
                                                webimageContainer.visible = false;
                                            }
                                        }
                                    }

 

 

Thanks in Advance.

Developer
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10
My Carrier: Aircel

Re: How to track HTTP error of webview in cascades

Hi All,

 

Please provide the suggestion for the above post. Is it possible or not?

 

Thanks in Advance. 

Developer
Posts: 237
Registered: ‎05-21-2012
My Device: BlackBerry RED Z10
My Carrier: WiFi

Re: How to track HTTP error of webview in cascades

What exactly you're trying to do? Maybe I can find some alternative workarounds, I can't find any signal or what in the webview to see the actual HTTP Error Code.

 

But in QT C++ you really can tell the http error code.

 

like this

 

void NemAPI::onComplete()
{
	QNetworkReply* reply 	= qobject_cast<QNetworkReply*>(sender());
	int status 				= reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
	QString reason 			= reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();

	qDebug() << "HTTP STATUS CODE: " QString::number(status) + ", REASON: " + reason; 
}

 

Developer
Posts: 508
Registered: ‎01-19-2011
My Device: My Trusty Red Plane
My Carrier: Outer Space

Re: How to track HTTP error of webview in cascades

Yes, it is possible. But you need to create additional stuff in Cpp. I suggest you create your own class

 


First of all, instead of setting the url directly to the WebView, create a QNetworkAccessManager, and check with a QNetworkRequest (and a reply, connected to the finished()-signal) whether it worked or not

 

QNetworkAccessManager* netManager = new QNetworkAccessManager();
if (netManager) {
   QUrl url(ImageUrl);
   QNetworkRequest networkRequest(url);
   QNetworkReply* networkReply = netManager->get(networkRequest);
   connect(networkReply, SIGNAL(finished()), this, SLOT(onReply()));
}

 then, in the onReply-function, check for errors

 

void App::onReply(QNetworkReply* reply) {
if (reply->error() != QNetworkReply::NoError) {

    //read the error
    QVariant httpCodeRaw = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    int httpCode = httpCodeRaw.toInt();

    qDebug() << "Image not available or any error: " << httpCode;

    return;
}


//..else, read all into a buffer
QByteArray buffer = reply->readAll(); //and do stuff

}

 

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o