Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Accessing Windows registry with Qt5
Forum Updated to NodeBB v4.3 + New Features

Accessing Windows registry with Qt5

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 14.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jonny83
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PSI-lbc
          wrote on last edited by
          #4

          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) ?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PSI-lbc
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved