Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test for default-constructed QFileInfo

Tags:

c++

qt

I want to use an optional argument of type QFileInfo. What is the canonical way to test if the caller provided a value or if the default was used?

// declaration
void foo(QFileInfo fi = QFileInfo());

// definition
void foo(QFileInfo fi)
{
    if ( /* what to test for: "is default" */ ) {

    }
}

Usually default-constructed Qt objects have something like isValid() or isEmpty(). However, there seems no such thing in QFileInfo.

One option would be fi.filePath().isEmpty(). Is there something better / simpler?

like image 792
Tim Hoffmann Avatar asked Nov 08 '22 18:11

Tim Hoffmann


1 Answers

The fi.filePath().isEmpty() seems to be the most straightforward and efficient, given that the effect of calling the default constructor is to create a QFileInfo with no file reference.

QFileInfo::QFileInfo()

Constructs an empty QFileInfo object.

Note that an empty QFileInfo object contain no file reference.

like image 146
Matteo Italia Avatar answered Nov 15 '22 06:11

Matteo Italia