PDA

View Full Version : Problem with QDir::cdUp()



nuntawat
29th March 2010, 00:07
Hello everyone. Now I want to access the parent directory by using cdUp(). For example, when the current directory is C:\SampleRoot\SampleFolder and I'd like to access C:\SampleRoot:



QDir tmpCurrDir = QDir::current();
tmpCurrDir.cdUp();
QString rootDir = tmpCurrDir.currentPath();


Even if there is a existed directory and cdUp() always return true, but when calling the currentPath() it will give C:\SampleRoot\SampleFolder not C:\SampleRoot. So what should I do?

Thanks a lot for everyone! :D

norobro
29th March 2010, 01:15
From the docs:

QString QDir::currentPath () [static]
Returns the absolute path of the application's current directory.

Use QDir:: path() instead
QString rootDir = tmpCurrDir.path();