QString str = "Hello world!"; QByteArray ascii = str.toAscii(); qDebug() << ascii; // Output: "Hello world!"
QString str = "¡Hola mundo!"; QByteArray ascii = str.toAscii(); qDebug() << ascii; // Output: "!Hola mundo!"In this example, the QString "¡Hola mundo!" (which contains a Spanish exclamation mark) is converted to ASCII encoding. The result is a QByteArray object containing the string "!Hola mundo!" with the exclamation mark replaced by a regular one. The package library for the QString class is part of the Qt C++ library.