I have to deploy a Qt Application on the following environments:
- Mac OS/X (>= Tiger 10.4 Intel Based, up to Snow Leopard 10.6.+)
- Windows XP
- Windows Vista
- Windows 7
I need a common access directory to put the License File, and I need every user of the machine to have read/write access to it – not only the administrator.
I checked many Qt functions like the following:
QString QDir::homePath()
QDir QDir::home ()
QString QDir::rootPath ()
QString QDir::tempPath ()
…but they all seem to return either user-specific or too-general paths.
Is there any Qt specific function to get a common “Applications Path”?
I ‘ve started to think about creating my own function taking into account the OS version,
but even in this case I feel a bit lost.
Do you know any good source to find what should be an appropriate path for each one for the OS I mentioned above?
This is an answer to my own question,
but I ‘ll wait to see if there is any better solutions.
(maybe there is a Qt function I missed).
I did the following hack using the QSettings class
(@thequark: +1 for the inspiration):
As you can see, I don’t really use the QSettings object but
I just get its filepath to see where Qt is going to store it.
It’s important to use:
interested in a file – not e.g. a
Windows registry position
a user-specific path
The above code yields the following results for (1) iniFilepath (2) commAppPath variables and the various O/S:
Mac Snow Leopard 10.6.7
Windows XP-SP3
Windows 7 (64) and Windows Vista SP2
Although it’s a hack, I think it’s a good solution
involving only internal Qt calls and not using any O/S specific functions.
If you have any better idea… please let me know.
EDIT – PS: In Mac OS-X the directory “/Library/Preferences” is not writable for a non-admin user. I finally used the directory “/Users/Shared”.