Accessing Windows registry with Qt5



  • I am currently trying to port a program I wrote in Qt4 to Qt5 which I have just downloaded. The one problem I have ran into is accessing the Windows registry. I did this in a very clean and simple way in Qt4 using a class called QSettings, but it does not appear to exist in Qt5, and from a Google search it seems it was taken out for some reason. I'm wondering if there is a straightforward way to do this in Qt5 or is it a case of using the RegOpenKeyEx(), RegGetValue(), RegSetKeyValue() methods directly?

    Any info much appreciated!


  • Moderators

    AFAIK it's still there in 5.0: "QSettings":http://qt-project.org/doc/qt-5.0/qtcore/qsettings.html



  • Indeed. It is still there, and it is still in Qt Core.



  • Curious as to why the QSettings methods work on XP but not Win7. I have verified that the settings are in a Win7 registry in same location as XP.

    Using the following code…

    @
    // extract Windows Registry settings and save the data we're interested in..Qt method
    QSettings settings( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft", QSettings::NativeFormat );

    // windows system identifiers..notcase sensitive..fyi
    QStringList wids;

    wids.append( "1:" + settings.value( "Windows NT/CurrentVersion/ProductId" ).toString().trimmed() );
    wids.append( "2:" + settings.value( "Internet Explorer/Registration/ProductID" ).toString().trimmed() );
    wids.append( "3:" + settings.value( "Cryptography/MachineGuid" ).toString().trimmed() );
    @

    Is there a permission or UAC setting that blocks access to the registry in Win7 (&8) ?



  • Well, modern windows systems do "virtualization" of some parts of the windows registry as well as the file system. So, if you try to write to HKEY_LOCAL_MACHINE for instance with an application that does not have elevated access rights, it ends up in a a part of the registry somewhere under the HKEY_LOCAL_USER settings.



  • Yep. Writing to the registry I can understand the need/requirement for elevated access privileges.

    It seems odd that reading from a registry entry is blocked. The above "setting.value" call returns an empty string..even though I have verified with regedit that the entry exists and contains string data.

    Thinking out loud..maybe the " QSettings settings()" instantiation is the problem..ie it's blocked by UAC or whatever and just returns an empty QSettings object.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.