Search code examples
c++qmlblackberry-10blackberry-cascades

How can I share unicode text via the invocation framework using QML and C++?


When I try sharing Unicode text on the BB10 Cascades framework, using the following code, all non-ASCII characters are converted to question marks at the invocation target, such as a BBM conversation or an email:

InvokeActionItem {
    title: qsTr("Share")
    id: shareCard

    query {
      mimeType: "text/plain"
    invokeActionId: "bb.action.SHARE"
    }

onTriggered: {
  data = getData();
    }
}

function getData(){

    return "¿Cómo están las cosas en el mundo hoy?";
}

Solution

  • To workaround this, create a helper function in C++ that converts QStrings to Utf8, and call this from within your QML / JavaScript functions:

    in your app.h

    Q_INVOKABLE
    QString Utf8EncodeString(const QString &encodeString);
    

    in your app.cpp

    QString app::Utf8EncodeString(const QString &encodeString) {
    return encodeString.toUtf8();
    }
    

    In the QML change the getData() function thusly:

    function getData(){
        return app.Utf8EncodeString("¿Cómo están las cosas en el mundo hoy?");
    }