我正在尝试检查提供的路径是否存在以及它是否是文件.
所以我写了这段代码:
#include <QFile>
#include <QFileInfo>
bool Tool::checkPath(const QString &path){
QFileInfo fileInfo(QFile(path));
return (fileInfo.exists() && fileInfo.isFile());
}
Run Code Online (Sandbox Code Playgroud)
我得到以下编译器错误:
Error: request for member 'exists' in 'fileInfo', which is of non-class type 'QFileInfo(QFile)'
Error: request for member 'isFile' in 'fileInfo', which is of non-class type 'QFileInfo(QFile)'
为什么?我一遍又一遍地阅读文档,但我无法理解.BTW Qt Creator建议我使用这些方法并完成它们.但编译器不喜欢它.
看起来很烦人的解析:编译器认为
QFileInfo fileInfo(QFile(path));
Run Code Online (Sandbox Code Playgroud)
是一个函数定义 QFileInfo fileInfo(QFile path);
使用类似的东西:
QFile ff(file);
QFileInfo fileInfo(ff);
bool test = (fileInfo.exists() && fileInfo.isFile());
Run Code Online (Sandbox Code Playgroud)