#include#include int main() { QString fileName = "example.txt"; QFileInfo fileInfo(fileName); QString absoluteFilePath = fileInfo.absoluteFilePath(); qDebug() << "Absolute file path:" << absoluteFilePath; return 0; }
#includeIn this example, we create an instance of QFileInfo for a file path "example.txt" and check if the file exists using the exists method. If it exists, we print "File exists" to the console; otherwise, we print "File does not exist". The package library for QFileInfo is Qt.#include int main() { QString filePath = "example.txt"; QFileInfo fileInfo(filePath); if (fileInfo.exists()) { qDebug() << "File exists"; } else { qDebug() << "File does not exist"; } return 0; }