[Qt-interest] QFile::exists on a folder
Thiago Macieira
thiago at kde.org
Thu Feb 11 14:59:48 CET 2010
Em Quinta-feira 11 Fevereiro 2010, às 14:02:31, Mika Rajala escreveu:
> > 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.
>
> The reason why i used open was to check that the path didn't point to a
> folder. The actual reading and opening of the file would happen later in
> another process, i was merely trying to validate that i was giving it a
> file it could open.
>
>
>
> > 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.
>
>
>
> Yes, i would like to gather any data about why the open operation failed,
> i.e. file didn't exist, no permission to open file, file parsing error or
> something. This so that it could be presented to the user.
Agreed, that's the way to go. In your original code, you were trying to guess
whether the open operation would fail before you tried it.
The only way to check if opening a file fails it actually try it. Remember that
there may be other reasons why an opening might fail, like read permissions
missing, sharing violations, out of memory, out of file descriptors, out of
system resources, etc. Some of those conditions won't show up in any test.
Besides, by trying to guess if it will fail to open, if it actually opens,
then you'll have wasted CPU time.
I recommend that *IF* it fails, then you should try and verify why that
happened. In most cases, the string returned by QIODevice::errorString() is
enough.
--
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/77ac53d9/attachment.bin
More information about the Qt-interest-old
mailing list