Solved

How to get the relative path from QFileDialog::getExistingDirectory

Posted on 2007-12-05
3
1,196 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

830 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