#include#include int main() { QFile file("file.txt"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QByteArray contents = file.readAll(); qDebug() << contents; file.close(); } return 0; }
#includeIn this example, we open the file "file.txt" in read-write text mode and read its contents using readAll(). We convert the contents to uppercase using toUpper() and write it back to the file using write(). We also seek back to the beginning of the file using seek(0) before writing to overwrite the original contents. Package library: Qt#include int main() { QFile file("file.txt"); if (file.open(QIODevice::ReadWrite | QIODevice::Text)) { QByteArray contents = file.readAll(); contents = contents.toUpper(); file.seek(0); file.write(contents); file.close(); } return 0; }