QByteArray ba("Hello World!"); ba.truncate(5); // ba now contains "Hello"
QByteArray sha256Hash = QCryptographicHash::hash(data, QCryptographicHash::Sha256); sha256Hash.truncate(16); // sha256Hash now contains the first 16 characters of the SHA-256 hash of dataIn this example, a SHA-256 hash is calculated for some data and stored in a byte array. The truncate function is then used to only keep the first 16 characters of the hash. This can be useful for storing compact representations of hash values. Package library: Qt Core (QCryptographicHash is part of Qt Core).