#include#include QString filePath = "/path/to/image.png"; QFileInfo fileInfo(filePath); if (fileInfo.suffix() == "png" || fileInfo.suffix() == "jpg" || fileInfo.suffix() == "jpeg") { qDebug() << "File is an image"; }
#includeIn this example, the suffix method is used to get the current extension of the file, and then a new file path is created with a new extension. Finally, the QFile::rename method is used to rename the file with the new extension. Package Library: Qt Core#include QString oldFilePath = "/path/to/file.txt"; QFileInfo oldFileInfo(oldFilePath); QString newFilePath = oldFileInfo.path() + "/" + oldFileInfo.completeBaseName() + ".docx"; QFile::rename(oldFilePath, newFilePath);