Check if a value registry exists with QSettings

Kazuma picture Kazuma · Dec 13, 2011 · Viewed 11.5k times · Source

What i'm trying to do is to check if a registry key (NOT VALUE, KEY) exists in the registry. I can't find any way to check that.

Idea?

Answer

mateuszb picture mateuszb · Feb 24, 2012

Using QSettings you can open the key's parent and retrieve the list of its keys. Use the function childGroups() to get the list of keys. It seems that "groups" in qt are keys in Windows registry.

This is the only way I found to check whether a key exists. In this code I look for the key "SearchedKey".

QSettings settings(
    "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths",
    QSettings::NativeFormat
);

if (settings.childGroups().contains("SearchedKey", Qt::CaseInsensitive))
    std::cout << "Key exists" << std::endl;
else
    std::cout << "Key doesn't exist" << std::endl;