#include#include int main() { QFile file; file.setFileName("myFile.txt"); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream stream(&file); stream << "Hello World!"; file.close(); } return 0; }
#includeIn this example, we create a QFile object and set its name to "myFile.txt". We then check if the file exists and, if it does, we use setFileName to change the name of the file to "newFile.txt" and then rename it back to "myFile.txt". Both examples use the QFile class provided by the Qt library.#include int main() { QFile file("myFile.txt"); if (file.exists()) { file.setFileName("newFile.txt"); file.rename("myFile.txt"); } return 0; }