Hi there! I'd like to know whether it is possible to find out if a registry key exists by the means of QSettings. I was trying to use QSettings::contains, but it doesn't work.
Printable View
Yes, VLC is a subkey and not a value. But I thought QSettings::contains is intended to be used for keys. Your code works, but I can't check key the way you said, because actually I don't need registry keys to be created (QSettings will create key if "HKEY_LOCAL_MACHINE\\Software\\VideoLan\\VLC" doesn't exist), therefore I need to use somethings like:
orCode:
bool exists = reg.contains("Software\\VideoLan\\VLC");
Or I don't know how to do it in a better way. But anyway this doesn't work.
Well no idea. As this is highly platform dependent anyway, why don't you use winapi directly?
Maybe somebody else knows how to do this with QSettings properly?Code:
#ifdef Q_OS_WIN #include "windows.h" #endif bool existsAndSuccess = false; #ifdef Q_OS_WIN HKEY hKey; existsAndSuccess = (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\VideoLan\\VLC", 0, KEY_READ, &hKey) == ERROR_SUCCESS); #endif qDebug() << existsAndSuccess;
Joh
yes, i ended up with this approach. but later i use qsettings anyway (because it is easier), therefore i thought to use qsettings for this check also and, generally, i was interested whether it is possible. ok, thank you.