Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QFileInfo exists() and isFile() error

Tags:

c++

file

qt

qfile

I'm trying to check if provided path exists and if it is a file.
So I wrote this piece of code:

#include <QFile>
#include <QFileInfo>


bool Tool::checkPath(const QString &path){
    QFileInfo fileInfo(QFile(path));
    return (fileInfo.exists() && fileInfo.isFile());
}

I get following compiler errors:

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)'

Why ? I'm reading through docs over and over again but I can't get it. BTW Qt Creator is suggesting me these methods and completes them. But compiler don't like it.

like image 701
Kousalik Avatar asked May 29 '14 10:05

Kousalik


1 Answers

It seems vexing parse: compiler thinks that

QFileInfo fileInfo(QFile(path));

is a function definition like QFileInfo fileInfo(QFile path);

Use instead something like:

QFile ff(file);
QFileInfo fileInfo(ff);
bool test = (fileInfo.exists() && fileInfo.isFile());
like image 184
asclepix Avatar answered Sep 30 '22 04:09

asclepix