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

New Contributor
Posts: 7
Registered: ‎01-23-2013
My Device: developer
My Carrier: developer

url encoding to utf-8 format in qml not in c++



please share a sample code to encode url in utf-8 format using qml not c++.

Posts: 85
Registered: ‎05-25-2012
My Device: Limited Edition Z10
My Carrier: Bell

Re: url encoding to utf-8 format in qml not in c++

It's actually really simple to drop down to C++ to encode the QML:


In your app's .cpp define a method to encode:


QByteArray SocialSamples::encodeQString(const QString& toEncode) {
    return toEncode.toUtf8();


In your constructor expose the C++ to the QML:


QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("_app", this);


And in your QML call your encoding method:


data = _app.encodeQString(lbl.text);





Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: url encoding to utf-8 format in qml not in c++

Depending on what exactly you want, either unescape(encodeURIComponent(url)) or just encodeURIComponent(url) may do what you need using only JavaScript (i.e. "using QML"). Check the results for some test cases, however, before relying on it for your needs.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!