PDA

View Full Version : Application for both Mac OS X and Windows. Windows OK. Mac OS X is not OK.



ZikO
4th September 2012, 14:01
Hi,

I need an advice from someone who has an experience in deploying applications for both platforms: Windows and Mac OS X.
The problem is that, in windows, all additional files such a local sort of database saved via QDataStream class, external binary resources (*.rcc), and translations (*.qm files) may be simply uploaded in the same directory and the application can find it. On the other hand, Mac OS X causes problems unless I provide absolute path. Unless I build all resources into an application, Mac cannot see them. I really need that run-time load mode available because the "database" file can be updated frequently.

I read about Mac OS X that it uses a special folder called "bundle". This is like folder with special directories: Contents/, MacOS/, and Resources/ etc. I thought I could upload the local database to Resources/ but it does not work--Mac still cannot see it. Any idea where I should keep all extra files so that they can be found my iOS system?


Thanks

PS.I just thought I could use something that returns the application's path. It is somehow solution but I was wondering if there is a better one as well.

spirit
4th September 2012, 14:39
Why don't you put the database into "Resources" and use relative path (E.g. ../Resources/database.db)?

ZikO
4th September 2012, 14:43
I am simply not familiar with file system of Mac OS X. I did not know that. Where does the "relative path" relate to? If I, for instance, use "file_name", in terms of bundle, where does it relate to?

spirit
4th September 2012, 14:52
The bundle it's just a special directory which have the following structure:
myapp.app
|----Contents
|----MacOS
|----myapp (this is the executable)
|----Resources (optionally)
...
(See Deploying an Application on Mac OS X (http://qt-project.org/doc/qt-4.8/deployment-mac.html).)
QCoreApplication::applicationDirPath() returns the directory where an executable is located.
So, putting this info together, you can get relative path to your database:


...
QString path = "mydatabase.db";
QString fullDatabasePath = QString::fromLatin1("%1/../Resources/%2")
.arg(QCoreApplication::applicationDirPath(), path);
...

Something like this.

ZikO
4th September 2012, 19:05
Thanks. It's working :)