#include#include int main() { QFileInfo file("C:/Users/example.txt"); qint64 size = file.size(); // size in bytes qDebug() << "File size: " << size; return 0; }
#includeIn this example, we create an object of the QFileInfo class and pass the path of the file we want to check. We then use the exists() method to check if the file exists and the size() method to check if its size is greater than zero. Depending on the results of these checks, we output a message to the console. These examples are part of the Qt core library.#include int main() { QFileInfo file("C:/Users/example.txt"); bool exists = file.exists(); qint64 size = file.size(); if(exists && size > 0) { qDebug() << "File exists and is not empty."; } else { qDebug() << "File does not exist or is empty."; } return 0; }