我正在开发一个将在 Windows 和 OS X 上分发的 Qt 应用程序。
该应用程序使用 SQLite 数据库。我可以在哪里保存两个系统上的数据库文件,以免在应用程序更新期间覆盖它?
注意事项 1:
我已经找到类似的 question关于OS X。答案是使用以下命令将其保存在 Application Support
中:
NSString * supportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
但我也需要在 Windows 上执行此操作。我是否也应该在 Windows 上使用此命令?
注释 2: 我正在使用 INI 文件来存储我的应用程序设置,如下所示:
QString path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
QSettings *settings = new QSettings(path+"/Settings.ini", QSettings::IniFormat);
path
变量是 C:/Users/user/AppData/Local/MyApplication/
(Windows)。
我可以把数据库文件放在同一个路径下吗?
谢谢。
最佳答案
QStandardPaths::AppDataLocation
是否满足您对此的要求?
来自qt documentation :
Returns a directory location where persistent application data can be stored. This is an application-specific directory. To obtain a path to store data to be shared with other applications, use QStandardPaths::GenericDataLocation. The returned path is never empty. On the Windows operating system, this returns the roaming path. This enum value was added in Qt 5.4.
关于c++ - 在 Windows 和 OS X 上,我可以在哪里存储 SQLite 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41598267/