-3

i got a QString blabla = qtfiledialog::getOpenFileName();

now blabla gives me the full path and the exe like: C:/Program Files/imanoob.exe

but i only want the path like: C:/Program Files/ how to do this?

stefan
  • 133
  • 1
  • 1
  • 6

2 Answers2

2
QFileInfo fileInfo(path);
const QString path = fileInfo.absolutePath();
Frank Osterfeld
  • 24,815
  • 5
  • 58
  • 70
  • Sorry for the "radical" modification. I just made sure that your answer can be copied and pasted while preserving the compilation success. – László Papp Jun 26 '14 at 13:05
  • @FinalContest You didn't assign the return value of absolutePath() – Frank Osterfeld Jun 28 '14 at 15:50
  • Sure, I was just forming the original code as it was. I was thinking about qDebug(), but then I decided to leave it with your personal preference so that I only change it to be compilable. Thanks. :) – László Papp Jun 28 '14 at 19:13
1

QString getExistingDirectory to get a directory path.

Or parse the returned string from getOpenFileName() by using QDir (probably QDir(blabla).path() although you need to check the API on the actual method to use).

laura
  • 7,280
  • 4
  • 35
  • 43