Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED]toAscii function depreciation what to use instead?



  • Hello, I want to write a small program, the program takes a STRING and converts it to ASCII code. The problem is that the toAscii function depreciated. I would like to know if there is another function that takes a STRING and converts it to ASCII.

    Thank You


  • Moderators

    Hi,

    Use QString::toLatin1()



  • Consider using toUtf8() so Unicode characters won't get destroyed!

    Note: The ASCII characters (0x00 to 0x7F) are bit-identical to ASCII in UTF-8.



  • Hi, if you characters are really ASCII characters, any ASCII-compatible encode can be used, such as Latin1/Latin2/.../Latin11/Latin13/.../Latin15/Utf8/GB18030/...

    All of these conversion can be done using QTextCodec::fromUnicode().

    QString has provided the convenient QString::toLatin1()/QString::toUtf8(), depending on the your local, QString::toLacal8Bit() can be used too.



  • Thank you for your replies, they helped me solve the problem. Thanks again


Log in to reply