【单纯判断一个文件是否存在,存在了又是否有内容?】

bool checkFile(const QString& filePath) {
    QFile file(filePath);

    // 判断文件是否存在
    if (!file.exists()) {
        qDebug() << Trans("文件不存在:") << filePath;
        return false;
    }

    // 判断文件是否为空
    if (file.size() == 0) {
        qDebug() << Trans("文件存在,但为空:") << filePath;
        return false;
    }
    else {
        qDebug() << Trans("文件存在且不为空:") << filePath;
        return true;
    }
}

你可能感兴趣的:(QT文件操作,qt)