Reputation: 549
The title says it all. I've seen many solutions to execute the oposite operation but not this way.
I'm using Qt to create a temporary file. If I get its name it will be something on the likes of:
QTemporaryFile tempFile;
tempFile.open();
qDebug() << tempFile.fileName();
// C:/Users/USERNA~1/AppData/Local/Temp/qt_temp.Hp4264
I have tried some solutions such as using QFileInfo:
QFileInfo fileInfo(tempFile);
qDebug() << fileInfo.filePath()
And QDir:
QDir dir(tempFile.fileName());
qDebug() << dir.absolutePath();
Without success.
Is there any solution for this using purely Qt? I know I can navigate the directory tree to find the full name but I was trying to avoid this, especially because of the possibility of two folders with the same prefix.
Upvotes: 3
Views: 1433
Reputation: 48186
the win32 function GetLongPathName is your answer.
QString shortPath = tempFile.fileName();
int length = GetLongPathNameW(shortPath.utf16(),0,0);
wchar_t* buffer = new wchar_t[length];
length = GetLongPathNameW(shortPath.utf16(), buffer, length);
QString fullpath = QString::fromUtf16(buffer, length);
delete[] buffer;
there is no pure Qt function for this because only windows does this (and Qt is meant to be portable)
Upvotes: 5