[Qt-interest] QFile::exists on a folder

Thiago Macieira thiago at kde.org
Thu Feb 11 13:16:27 CET 2010


Em Quinta-feira 11 Fevereiro 2010, às 13:01:50, David Ching escreveu:
> "Mika Rajala" <mika_rajala_2 at hotmail.com> wrote in message
> news:BLU141-W34744024A00C977722A8CEE64E0 at phx.gbl...
> 
> > anyway, i think it's better to use QFileInfo to check that it's a file.
> > Although trying to open it is a valid solution as well.
> 
> The QFile::exists() and QFileInfo solution together to is the best way
> because it tests exactly what you want to know, not approximate it by
> another technique.  Such as trying to open the file.  Though rare, the file
> could exist but fail to be opened due to e.g. sharing violation or
> permission failure.

Indeed, but the OP was trying to open the file anyway. That's why I was 
questioning why he was trying to figure out if a file existed before opening.

If a file cannot be opened, then it may be in his interest to check why that 
happened, if it's a temporary condition or not.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100211/877dd02b/attachment.bin 


More information about the Qt-interest-old mailing list