【问题标题】:Qt Mac App Store application rejected for file system requitementsQt Mac App Store 应用程序因文件系统要求而被拒绝
【发布时间】:2012-05-30 13:08:48
【问题描述】:

我有一个提交给 Apple Mac App Store 的 Qt 应用程序。它被拒绝写入〜/Library/Preferences/com.mycompany.myapp

这是我收到的消息:

2.30

The application accesses the following location(s):

'~/Library/Preferences/com.nourayn.AlMosaly.plist'

The application may be 

* creating files
* writing files
* opening files for Read/Write access (instead of Read-Only access)

in the above location(s).

如何解决这个问题?

【问题讨论】:

    标签: macos qt store


    【解决方案1】:

    我认为您正在使用 QSettings 保存应用程序设置。您的代码可能如下所示:

    QApplication app;
    app.setOrganizationDomain("nourayn.com");
    app.setApplicationName("AlMosaly");
    QSettings settings; // this creates a .plist file under ~/Library/Preferences
                        // which is non-MacAppStore-friendly
    

    相反,您可以使用明确指定的文件名创建 QSettings:

    app.setOrganizationDomain("nourayn.com");
    app.setApplicationName("AlMosaly");
    QSettings settings(yourAppDataFolder+"/settings.plist", QSettings::NativeFormat);
                        // this writes to the file you specified
    

    如果您在应用中的多个位置使用 QSettings,这样做可能会稍微轻松一些:

    // in main.cpp
    app.setProperty("SettingsFileName", yourAppDataFolder+"/settings.plist");
    
    // in someotherfile.cpp
    QString settingsFileName = qApp->property("SettingsFileName").toString();
    QSettings settings(settingsFileName, QSettings::NativeFormat);
    

    此外,如果您在 ~/Library/ 中有一个 com.trolltech.plist 文件(存储 Qt 全局设置),您可能需要迁移到 Qt 4.8.1。更多信息在这里: http://qt-project.org/doc/qt-4.8/qsettings.html#changing-the-location-of-global-qt-settings-on-mac-os-x

    【讨论】:

    • 我在许多不同的地方使用了很多 QSettings,我可以通过一个 Api 调用来设置设置位置,而不是在我创建的每个 QSettings 对象的 QSettings 构造函数中设置它吗?
    • 编辑了我的答案来解决这个问题。您也可以按照@jdi 的建议查看 QSettings::setPath() ,但我没有尝试过使用它。
    【解决方案2】:

    苹果开发者文档解释了使用文件系统时允许的内容。您可以选择使用 API 调用为您处理它,否则您的位置和命名数量有限。 Read in detail here

    Your application may write to the following directories:
    ~/Library/Application Support/<app-identifier>
    ~/Library/<app-identifier>
    ~/Library/Caches/<app-identifier>
    

    如果您使用 QSettings,它将选择系统位置来存储首选项,那么您可能需要更改该方法以更直接地控制目标。

    对于 QSettings,请阅读有关如何根据平台/范围将路径更改为首选位置的文档:http://qt-project.org/doc/qt-4.8/qsettings.html#setPath

    QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, 
                        "/path/to/location");
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多