Qt App. Deployment on Mac/XP/Vista/Windows 7: Any common access directory to put the License File?
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开发者_JAVA百科 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):
---------------------------------------------
QString orgName = "fooOrg";
QString appName = "fooApp";
QSettings qsettings(QSettings::IniFormat, QSettings::SystemScope, orgName, appName);
QString iniFilepath = qsettings.fileName();
QString commAppPath = iniFilepath.left(iniFilepath.length() -
QString("/fooOrg/fooApp.ini").length());
---------------------------------------------
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:
- QSettings::IniFormat: Because we are interested in a file - not e.g. a Windows registry position
- QSettings::SystemScope: Because we want a machine specific and not 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
- /Library/Preferences/Qt/fooOrg/fooApp.ini
- /Library/Preferences/Qt
Windows XP-SP3
- C:/Documents And Settings/All Users/Application Data/fooOrg/fooApp.ini
- C:/Documents And Settings/All Users/Application Data
Windows 7 (64) and Windows Vista SP2
- C:/ProgramData/fooOrg/fooApp.ini
- C:/ProgramData
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".
I am a n00b in Qt too so I am not sure if this is the best option but how about using QSettings
to get the path to license file from a settings/configuration file. This file with proper values should be created by the installer. Installer can take care of using some default values specific to the OS or even ask user at the time of installation, so you application is independent of the OS. QSettings
has persistence so you don't have to bother about reading, writing on to a file.
Have a look at QDesktopServices::storageLocation.
QDesktopServices::DataLocation enum seems appropriate.
For Windows 2000 and higher, this folder is known as CSIDL_COMMON_APPDATA.
精彩评论