Solved: How to include unicode in QString???

  • hello Gurus,

    I have the following code to replace the &#xxxx unicode decimal signs into \u0628 hexas. But the funny result is that

    When I give the string manually it is converted, when it gets from previous function it is not converted.
    Any body focus my mistake?


    qDebug() << "system name:"      << QLocale::system&#40;&#41;.name(&#41;;
    qDebug(&#41; << "codecForCStrings:" << QTextCodec::codecForCStrings()->name();
    qDebug() << "codecForLocale:"   << QTextCodec::codecForLocale()->name();
    // convert string from &#xxxx; format to /u hex format to be used for unicode
    int index; //QString name;
    QString name="&#1578;&#1578;&#1578;&#1579;&#1578;&#1573;&#1578;&#1572;&#1606;&#1601;&#1606;&#1606;&#1606;&#1606;&#1606;&#1606;&#1578;&#1606;&#1578;";  //bidi example
    int off=0;
    QString Outp;
    QRegExp [removed]"&#[0-9][0-9][0-9][0-9];"); //
    index=expression.indexIn(name, off);
    qDebug () << "index" << index;
    int length = expression.matchedLength();
    if (index==-1) break;
    QString v;
    QString re;
    qDebug() << "v=" &lt;&lt; v &lt;&lt; "re=" &lt;&lt; re;
    uint r=v.toInt(0,10);
    qDebug() &lt;&lt; "int=" &lt;&lt; r;
    uint decimal = r;
    QString haxadecimal;
    if (haxadecimal.length()==3)
        haxadecimal= "\\u0" + haxadecimal;
    qDebug() << "hexa" << haxadecimal;
    qDebug() << "inloop output" << name;
    qDebug () << "output" << name; // name = \u062a\u062a
    // now the problem is : When the output name is feeded to the next part
    // the qDebug is not shown in unicode format. However if the output is given
    // manually to the name string, then it is shown correctly
    name = "\u062a\u062a"; // \u062a\u062b\u062a\u0625\u062a\u0624\u0646\u0641\u0646\u0646\u0646\u0646\u0646\u0646\u062a\u0646\u062a";
    QByteArray utf8;
    qDebug() << "utf8" << name;  // << utf8.toHex();
    QByteArray latin1;
    qDebug() << "Latin1" << name ;  //<< latin1.toHex();
    QTextCodec *codec = QTextCodec::codecForName("latin1");
    QByteArray encodedString = codec->fromUnicode(name);
    qDebug() << "ISO 8859-1" << name; // << encodedString.toHex();


  • solved:

    QChar a=QChar::Qchar(hexanumber of the character)

    Then add the QChar into a string

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.