0

I am working on a Qt project which maps vowels onto a chart that have the *.sym format.

My goal is to load an initial IPA chart like this.

I have the *.sym files and I can load them after my application starts, but I'm not really sure where my executable is executing.

I have a directory format (after building) like this

Project
|_ Source
|_ Build
  |_ Source
    |_ Charts
      |_ load_at_start.sym
    |_ Project.app
      |_ Contents
        |_ MacOS
          |_ Project (executable)

This makes using an fopen call quite difficult. I assumed that fopen would consider the current working directory as the place where the executable rested, so I tried something like this...

    FILE *stream = fopen("./../../../charts/load_at_start.sym", "r");

but it doesn't work. Can anyone help me?

erip
  • 16,374
  • 11
  • 66
  • 121
  • 3
    Your path is a relative path and so it relative to the working directory. Perhaps the working directory is not what you think it is. Did you check what it is? – David Heffernan Nov 13 '14 at 06:50
  • 1
    try printing out your current directory when the exe starts: http://stackoverflow.com/questions/4807629/how-do-i-find-the-current-directory – user2240431 Nov 13 '14 at 07:00

1 Answers1

0

You'll want to make sure the .sym file ends up within the app bundle (the .app directory), specifically under Contents/Resources.

Then you can use QCoreApplication::applicationDirPath to obtain the directory of your application (e.g. "/Applications/Project.app/Contents/MacOS/") and append the relative path to your file (e.g. "../Resources/charts/load_at_start.sym").

Something like this:

QDir dir(QCoreApplication::applicationDirPath());
dir.cd("../Resources/charts");
FILE* stream = fopen(dir.filePath("load_at_start.sym").toUtf8().constData());

Although you might want to consider using Qt's I/O facilities instead of C's.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157
  • This worked for me basically. I haven't tested it on the other platforms, though. I'll comment later after Linux test has been conducted. Thanks a lot! – erip Nov 15 '14 at 04:25