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
Highlighted
Developer
Posts: 324
Registered: ‎03-10-2010
My Device: Bold 9780, DevAlpha
My Carrier: Vodafone CZ
Accepted Solution

QNetworkAccessManager bug? Missing symbol š

[ Edited ]
void WebDownloader::httpGet(const QUrl& url) {
	mLoading = 0;
	setUrl(url);
	QNetworkRequest request = QNetworkRequest(url);
	request.setHeader(QNetworkRequest::ContentTypeHeader, "text/html; charset=iso-8859-1");
	QNetworkReply * reply = mNetManager->get(request);
	connect(reply, SIGNAL(finished()), this, SLOT(httpLoaded()));
	connect(reply, SIGNAL(downloadProgress ( qint64 , qint64 )), this,
			SLOT(dowloadProgressed(qint64,qint64)));
	connect(reply, SIGNAL(error(QNetworkReply::NetworkError code)), this, SLOT(httpError(errorCode)));
}

void WebDownloader::httpLoaded() {

	QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
	m_httprequest = QString(reply->readAll());  // symbol š missing from source?!!!
	reply->deleteLater();
}

 

Just found that symbol "š" is missing after HTTP request processed.

 

You can test it yourself: http://blackberry.mediatwins.com/test_s.html

 

Source contains: Matuška

QNetworkReply returns: Matuka 

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: QNetworkAccessManager bug? Missing symbol š

[ Edited ]

Try
QByteArray data = reply->readAll();
m_httprequest = QString::fromUtf8(data.constData(), data.size());


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 324
Registered: ‎03-10-2010
My Device: Bold 9780, DevAlpha
My Carrier: Vodafone CZ

Re: QNetworkAccessManager bug? Missing symbol š

[ Edited ]

It is not UTF-8, it is ISO-8859-1, romanian symbol.

 

All others (like a á) processed without error, but this symbol just miss from html source.

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: QNetworkAccessManager bug? Missing symbol š

[ Edited ]

I opened this file with MC and it displays it correctly in CP1250 encoding.
When I switch to ISO 8859-1 the symbol disappears.
Can you please check the encoding? CP1250 has some of ISO-8859-1 symbols rearranged.

 

Btw, it's better to use ::fromLatin1 and to specify data size explicitly, otherwise the program will crash if malformed data is received. Default conversion expects NULL-terminated data.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 324
Registered: ‎03-10-2010
My Device: Bold 9780, DevAlpha
My Carrier: Vodafone CZ

Re: QNetworkAccessManager bug? Missing symbol š

::fromLatin1, ::fromAscii does not helps.

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: QNetworkAccessManager bug? Missing symbol š

I meant to say that the file is in CP1250 encoding, not ISO-8859-1.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 324
Registered: ‎03-10-2010
My Device: Bold 9780, DevAlpha
My Carrier: Vodafone CZ

Re: QNetworkAccessManager bug? Missing symbol š

[ Edited ]

Okay. I've fixed URL -- now it in ISO-8859-1, but symbol miss...

 

http://blackberry.mediatwins.com/test_s.html

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: QNetworkAccessManager bug? Missing symbol š

Redownloaded... It says

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

but the text is still CP1250.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 324
Registered: ‎03-10-2010
My Device: Bold 9780, DevAlpha
My Carrier: Vodafone CZ

Re: QNetworkAccessManager bug? Missing symbol š

			QByteArray encodedString = reply->readAll();
			QTextCodec *codec = QTextCodec::codecForName("Windows-1250");
			m_httprequest = codec->toUnicode(encodedString);