osx - How to retrieve the location of an item in the Resources folder of an OS X application bundle, in Qt -


I need to obtain the application directory or executable path.

I've found that

  QString appPath = QCoreApplication :: applicationDirPath ();  

There will be a way to do this.

But when I run, I get an error:

  QCoreApplication :: applicationDirPath:  

If I run the Quark application I try to make an example, though I am creating errors ...

  Error: No matching function: Using QApplication instead of QCoreApplication, I get a similar error.  

This call is not created by the main () which is an application type class instantly ... it is very far from a config class.

How is this done?

Qt 4.8

Note: What I'm trying to get is the actual app directory (for Mac, I will use it to create a full path for content / resources ).

The relative path was not used (when I used to print the path before the relative path part, and failed to load the file I tried to load) < Instead of pre> @ / myapplication.app/Contents/Resources/myfile

  path / myapplication.app / content / resource / Myfile  

To use the file or object in the resource folder, it would be possible executable Start from the place and work from there Please. However, if the apple decides to change the format of the bundle, then this can be a problem.

As QT does not provide it directly, I suggest using the Apple Core Foundation, which can be used within QT applications. Suppose we want a resource named "itemName", which resides in the resource folder and we will get our full path in the path in the QString item: -

  // Find the object path. QString itemPath; {CFRRF APR URLRF; AppUrlRef = CFBundleCopyResourceURL (CFBundleGetMainBundle), CFSTR ("itemName"), CFRT ("bundle"), null); CFStringRef MacPath = CFURKPFile System Path (APRLLR, KCFRRPOSISXTPSTL); Madpath = CF stringGet's StringPrint (McPath, CF StringGetSystem Encoding); // The main foundations should be issued CFRs (APRLLF); CFRelease (macPath); }  

To use core forward functions, just include in your repatriation file: -

  #include & lt; Corefoundation / CFBundle.h & gt;  

Add relevant structure to project file (.pro)

  LIBS + = -framework corinthation  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -