[Qt-interest] QFileInfo doesn't work after QDir::setCurrent. Bug?

Nikos Chantziaras realnc at arcor.de
Thu Jun 10 20:10:38 CEST 2010


Consider this:

   QFileInfo finfo("test.txt");
   qDebug() << "exists:" << finfo.exists();

(Make sure "test.txt" exists in the current directory.) This prints 
"true", as expected.

Now consider this:

   QFileInfo finfo("test.txt");
   QDir::setCurrent("/home");
   qDebug() << "exists:" << finfo.exists();

This prints "false".  finfo is not functional anymore and can't be used 
to get any valid information about "test.txt".

And to top it off:

   QFileInfo finfo("test.txt");
   qDebug() << "exists:" << finfo.exists();
   QDir::setCurrent("/home");
   qDebug() << "exists:" << finfo.exists();

This prints "true" 2 times, and finfo works and can be used normally. 
Seems that calling any method on finfo fixes this.

Have I found a bug in Qt, or is this normal?

Qt 4.6.3 and 4.7.0 beta1, both 64-bit on Linux.



More information about the Qt-interest-old mailing list