Solved

How to get the relative path from QFileDialog::getExistingDirectory

Posted on 2007-12-05
3
1,221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is about my first experience with programming Arduino.
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…
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…

734 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