用.app文件打开 [英] fopen with a .app file

查看:94
本文介绍了用.app文件打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个Qt项目,该项目将元音映射到具有* .sym格式的图表上.

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

我的目标是加载初始IPA图表,例如.

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

我有*.sym个文件,可以在应用程序启动后加载它们,但是我不确定执行可执行文件的位置.

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)

这使得使用fopen调用非常困难.我以为fopen会将当前工作目录视为可执行文件的存放位置,所以我尝试了类似的方法...

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?

推荐答案

您需要确保.sym文件位于应用程序包(.app目录)中,特别是在目录/资源下.

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

然后,您可以使用 QCoreApplication :: applicationDirPath 来获取应用程序的目录(例如"/Applications/Project.app/Contents/MacOS/"),并将相对路径附加到文件中(例如"../Resources/charts/load_at_start.sym").

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").

类似这样的东西:

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

尽管您可能要考虑使用Qt的I/O功能而不是C的功能.

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

这篇关于用.app文件打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆