[Qt-interest] QFileInfo doesn't work after QDir::setCurrent. Bug?
Nikos Chantziaras
realnc at arcor.de
Thu Jun 10 20:20:53 CEST 2010
Thanks. This explains it, I guess.
One thing though. Even if I use a relative path, if I call
finfo.absoluteFilePath() at least once, then it keeps working even after
changing the current directory. I wonder why that is (this is the
reason I thought this is a bug.)
On 06/10/2010 09:18 PM, Scott Aron Bloom wrote:
> That's because your QFileInfo is based on a relative path.
>
> The moment you change the current directory, its looks in that current
> directory.
>
> If you want it to work, use an absolute path.. Or use a relative path,
> have QFileInfo determine the absolute path, then create a new QFileInfo
> off that abs path...
>
> QFileInfo finfo( "test.txt" );
> If ( finfo.exists() )
> Finfo = QFileInfo( finfo.absoluteFilePath() );
>
> Im not at my dev box, so my syntax might be off a bit :)
>
> This isn't a bug...
>
> Note, if you used QFile, and opened it, it wouldn't be an issue at all.
>
> Scott
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Nikos
> Chantziaras
> Sent: Thursday, June 10, 2010 11:11 AM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] QFileInfo doesn't work after QDir::setCurrent.
> Bug?
>
> 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.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list