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 Knowledge Base

Using Invocation with UTF-8 Characters from QML

by BlackBerry Development Advisor on ‎04-10-2015 02:45 PM (1,448 Views)

When you work in QML and JavaScript, the Unicode character set is used.  If you attempt to share UTF-8 characters that are either hard coded in QML or created using JavaScript, you may find some characters don't appear correctly in the application that is being invoked.  These characters will usually appear as squares or question marks.


You can work around this by converting the Unicode string into UTF-8.  To do this, you will need to create a method in C++ that does the conversion, which you can call from QML.  Here is an example of a method that will perform this conversion in C++.


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


Assuming the method above is exposed as a Q_INVOKABLE method and the class is exposed as the QML variable _app, here is how it can be used when invoking from QML.


Button {
       id: shareUTF8
       text: "Share UTF8 Text QML"
       onClicked: {
           invokeQuery.data =  _app.encodeQString("Pourquoi ça ne marche pas?");
       attachedObjects: [
           Invocation {
               id: invokeShareUTF8
               query {
                   InvokeQuery {
                       id: invokeQueryUTF8
                       mimeType: "text/plain"
                       onQueryChanged: invokeShare.query.updateQuery()




Users Online
Currently online: 13 members 701 guests
Please welcome our newest community members: