Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get the relative path from QFileDialog::getExistingDirectory

Posted on 2007-12-05
3
Medium Priority
?
1,253 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Loops Section Overview

963 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