Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a value registry exists with QSettings

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?

like image 529
Kazuma Avatar asked Dec 13 '11 05:12

Kazuma


1 Answers

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;
like image 167
mateuszb Avatar answered Oct 15 '22 11:10

mateuszb