Convert text in other encoding qt



  • I am using QByteArray.
    I want to ask about which other conversions exist. I am normally using toLatin1 but i would try with others.

    datoss = "|@|" + ui->textocuenta->text().toLatin1() + "|@|"
    i am trying to use other conversion. Only that.


  • Moderators

    @RIVOPICO
    use QTextCodec::fromUnicode()

    QTextCodec * codec = QTextCodec::codecForName("CodecName")
    QByteArray data = codec->fromUnicode( utf8Str );
    

    For a possible list of codec values you can use QTextCodec::availableCodecs()



  • but in this example for example: how will be? thanks in advance. It is for having one example.
    datoss = "|@|" + ui->textocuenta->text().toLatin1() + "|@|"


  • Moderators

    @RIVOPICO

    QTextCodec * codec = QTextCodec::codecForName("CodecName")
    QByteArray encodedData = codec->fromUnicode( ui->textocuenta->text().toUtf8() );
    encodedData = QByteArray("|@|") + encodedData + QByteArray("|@|");
    


  • when i use this my tool crash i put the class and ; symbol that you forgot and crash. Show me the client stop working.


  • Moderators

    @RIVOPICO Did you check that codec is not null?

    QTextCodec * codec = QTextCodec::codecForName("CodecName");
    

    What did you pass as codec name?
    In such situations you should always debug first to see where and why your app crashes.



  • sorry ok you are right now Works fine thx


Log in to reply
 

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