Results 1 to 5 of 5

Thread: QSettings putting Windows registry keys in the wrong location

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default QSettings putting Windows registry keys in the wrong location

    QSettings putting Windows registry keys in the wrong location. Here's how I'm using it:

    Qt Code:
    1. QSettings *registry = new QSettings("HKEY_CLASSES_ROOT\\SystemFileAssociations", QSettings::NativeFormat);
    2. registry->setValue("TEST", "Test");
    To copy to clipboard, switch view to plain text mode 

    It's putting a subkey "TEST" with a value "Test" properly, but it's saving it here instead:
    HKEY_CURRENT_USER\Software\Classes\SystemFileAssoc iations (Ignore the space... the forum is messing it up)

    How do I make it place the key where I tell it to place it, instead of where it thinks I should place it?


    [edit:] Qt 4.7 on Windows 7 32bit Home and Premium
    Last edited by ComServant; 26th October 2011 at 22:35.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSettings putting Windows registry keys in the wrong location

    Are you running the program with administrative rights?

  3. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSettings putting Windows registry keys in the wrong location

    Just tried running as admin. No go.
    Plus, I don't want my users to have to run as admin to use the tool.

    I found this post: http://www.qtcentre.org/threads/1816...0772#post90772
    Seems to imply QSettings does not give full access to the registry, which is a shame.

    Qt ought to have a QWindowsRegistry class for wrapped native access, on the Windows version of Qt. Looking at the ugly convoluted legacy-filled crummy native Windows functions, and seeing if I can use them properly.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSettings putting Windows registry keys in the wrong location

    You are trying to modify a global file association by writing into that area. You will not be able to do that as an unprivileged user.

    I cannot reproduce your symptoms with a test program on XP and Win 7 (32).
    • On XP, where there are no restrictions, the TEST value was written where expected.
    • On Windows 7.
      • When "Run as Adminstrator..." is used the application writes where you are expecting (and the value is mirrored in HKLM/Software/Classes/SystemFileAssociation)
      • As an unprivileged user the TEST value was not written anywhere in my registry regardless of whether the application was being UAC virtualised (manifest or not). I was expecting registry virtualisation to have moved the errant attempt into the virtual store, but this does not seem to have happened.
    The HKCU registry key you mention does not appear on my machine at all.

  5. #5
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSettings putting Windows registry keys in the wrong location

    Qt Code:
    1. this->registry = new QSettings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
    2. this->registry->setValue("\\SystemFileAssociations\\.png\\shell\\View image tiled\\command", "T12345");
    To copy to clipboard, switch view to plain text mode 

    Results in "HKEY_CLASSES_ROOT" having an entry *named* "HKEY_CLASSES_ROOT/SystemFileAssociations/.png/shell/View image tiled/command" with a value of "T12345"


    Qt Code:
    1. this->registry = new QSettings("HKEY_CLASSES_ROOT\\SystemFileAssociations\\.png\\shell\\View image tiled\\command", QSettings::NativeFormat);
    2. this->registry->setValue(".", "T12345");
    To copy to clipboard, switch view to plain text mode 

    Results in nothing being created if in non-admin, but created in the right spot if running as admin.
    So setValue() assumes the first parameter is a complete name, and not a path to a name, even if broken with slashes.

    Alright, so I need elevated permissions, and I need to use a different QSettings for each key I want to edit.
    I'll try and have my current program execute the settings window as a sub-program or something.

Similar Threads

  1. QSettings and Windows registry - removing a key
    By lxman in forum Qt Programming
    Replies: 1
    Last Post: 29th July 2011, 20:43
  2. Replies: 1
    Last Post: 24th June 2011, 11:11
  3. reading windows registry
    By bhogasena in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2009, 09:36
  4. Replies: 1
    Last Post: 19th September 2008, 15:43
  5. [QSettings] Why limiting to plain file or registry ?
    By lauranger in forum Qt Programming
    Replies: 8
    Last Post: 13th September 2006, 14:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.