Search code examples
qtregistryqsettings

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?


Solution

  • EDIT:

    In 2011 I wrote:

    The registry is a Windows concept and doesn't fit Qt's cross-platform notions. You will have to use the Windows API or a C++ wrapper for it.

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms724875(v=vs.85).aspx

    http://msdn.microsoft.com/en-us/library/xka57xy4(v=vs.80).aspx

    If your needs are more abstract for your application to save and restore its own settings, Qt has a cross-platform design of something called QSettings.

    Depending on the nature of the setting and the platform, will store these in the registry or in a file/etc.

    But it appears in the answer by @mateuszb that QSettings can open Windows keys if you use QSettings::NativeFormat:

    http://doc.qt.io/qt-5/qsettings.html#Format-enum

    I'd still suggest that if you are hardcoding something like "HKEY_LOCAL_MACHINE" into your source, that you are not really in the spirit of abstracting your code across platforms in the way that Qt intends. But you apparently can (at least in recent Qt versions) do this without digging beneath Qt and calling the Windows registry APIs.