#include#include int main() { QFileInfo fileInfo("/path/to/myfile.pdf"); QString suffix = fileInfo.completeSuffix(); if (suffix == "pdf") { qDebug() << "This is a PDF file!"; } else { qDebug() << "This is not a PDF file."; } return 0; }
#includeThese examples are part of the Qt library, which is included in the Qt SDK. Therefore, the package/library required to use them is the Qt SDK.#include int main() { QDir directory("/path/to/my/directory"); QStringList filters; filters << "*.jpg" << "*.png" << "*.bmp"; directory.setNameFilters(filters); QFileInfoList files = directory.entryInfoList(); foreach (QFileInfo fileInfo, files) { QString suffix = fileInfo.completeSuffix(); if (suffix == "jpg" || suffix == "png" || suffix == "bmp") { // Process image file } } return 0; }