Solved

How to get the relative path from QFileDialog::getExistingDirectory

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 47
count7 challenge 12 70
changePi Challenge 15 76
Path of Workbook 3 45
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now