Solved

How to get the relative path from QFileDialog::getExistingDirectory

Posted on 2007-12-05
3
1,187 Views
Last Modified: 2012-06-22
im creating a list of directories which are supposed to be listed as relative path to the application.

but with QFileDialog::getExistingDirectory I always get the absolute path.

Is there a way to change the absolute path to relative path? Or any other way to get the relative path?


I want the string     data/source1   returned . The app is running in the directory above data.
What I get returned is the absolute path /home.local/bla/etc/moreEtc/data/source1



Thank you in advance
0
Comment
Question by:Endelm
3 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 20410533
The problem with filepaths is that they may contain symbolic link names and therefore are difficult to map.

If you know that the absolute path you get from getExistingDirectory is a sub folder of the executable path, you can do

#include <sys/stat.h>

           
          string exe = "myexe";
          string dlgpath = dlg.getExistingDirectory();
          string path = dlgpath;
          int pos = path.length();
          struct stat fs;
          int ret;

          while ((ret = stat((path + '/' + exe).c_str(), &fs)) != 0 && 
                     (pos = path.rfind('/')) != string::npos)
          {
                 path.resize(pos);
          }      
          if (ret == 0)  
               dlgpath = dlgpath.substr(path.length());


Regards, Alex
 
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20633897
Forced accept.

Computer101
EE Admin
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A short article about a problem I had getting the GPS LocationListener working.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question