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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With