[Qt-interest] QFile::exists on a folder
Thiago Macieira
thiago at kde.org
Thu Feb 11 11:47:53 CET 2010
Em Quinta-feira 11 Fevereiro 2010, às 10:30:14, Mika Rajala escreveu:
> Hi
>
> Am I doing something wrong.
>
> I want to check if a file exists prior to opening it, and I do something
> like this:
>
> void myClass::openFile(const QString & _file)
> {
> QFile fileToOpen(_file);
> if(fileToOpen.exists() == false)
> {
> printf("Error file:\"%s\" doesn't exist",
> _file.toStdString().c_str());
> }
> ....
> }
<
> It all works fine, until that function is called with an absolute path to a
> directory.
Why don't you simply try to open? I mean, why are you checking if a file exists
before you open it?
If it doesn't exist, it will fail to open anyway. And you can't open a
directory with QFile, so you also get an error there (an EISDIR).
--
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/6d443794/attachment.bin
More information about the Qt-interest-old
mailing list