gpt4 book ai didi

windows - QSettings 用反斜杠替换斜杠(注册表)

转载 作者:可可西里 更新时间:2023-11-01 10:35:03 26 4
gpt4 key购买 nike

我使用 QSettings 读取注册表。我想阅读的关键是:

HKEY_LOCAL_MACHINE\SYSTEM\Setup\Source OS (Updated on 8/1/2015 02:45:41)

由于键名 Source OS (Updated on 8/1/2015 02:45:41) 是动态的,所以我直接打开

QSettings settings("HKEY_LOCAL_MACHINE\\SYSTEM\\Setup", QSettings::NativeFormat);

并通过 settings.childGroups() 递归运行并以此构建我的 key :

QString key = settings.fileName() + "\\" + settings.group();

但这会导致:

\HKEY_LOCAL_MACHINE\SYSTEM\Setup\Source OS (Updated on 8\1\2015 02:45:41)

如您所见,斜线现在变成了反斜线,我无法区分名称和路径部分。

知道为什么 QSettings 将斜杠转换为反斜杠吗?

最佳答案

来自 QSettings documentation :

Do not use slashes ('/' and '\') in section or key names; the backslash character is used to separate sub keys (see below). On windows '\' are converted by QSettings to '/', which makes them identical.

通常,动态注册表项名称的想法不太好。我认为更好的方法是在您的 key 中创建两个单独的值 – Source OSUpdated On 值。

关于windows - QSettings 用反斜杠替换斜杠(注册表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31923850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com