Results 1 to 7 of 7

Thread: QSettings windows registry reading fails on certain keys

  1. #1
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QSettings windows registry reading fails on certain keys

    Hi all

    I'd like to read the value of a certain key in the registry. Code is easy enough:

    Qt Code:
    1. QSettings settings("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM", QSettings::NativeFormat);
    2. QStringList keyList = settings.allKeys();
    3. QString sComPort = settings.value(keyList[0], "").toString();
    To copy to clipboard, switch view to plain text mode 

    Note that I started with a key string, but as I saw there was something wrong I've tested it with reading the available keys and using that buffer to make sure the key is correct. The problem is that the value is always empty, even though there is a key with a value.

    Going deeper into this, the key name is e.g. "/Device/Serial0". And this is where the problem starts. Digging into the QSettings code, value() will call actualKey() which calls normalizedKey(). normalizedKey() returns a string that never starts nor ends with a slash. So it is actually using "Device/Serial0" which doesn't exist!

    Can we somehow ask the value without adjusting the key? It seems weird that the Qt lib changes our requested key behind our backs...

  2. #2
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSettings windows registry reading fails on certain keys

    Does anyone have an idea on how to solve this?

  3. #3
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings windows registry reading fails on certain keys

    Reading the registry in this case - is a bad idea.
    Look ready implementation, e.g. for QtSerialPort (class SerialPortInfo) or another libraries.

    To enumerate devices need to use Windows SetupAPI.

  4. #4
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSettings windows registry reading fails on certain keys

    Thanks for the idea. I've tried this with SerialPortInfo::availablePorts(), but the port I need doesn't really "exist" as a serial port (it is some kind of virtual comm device). So unfortunately this won't work for me.

  5. #5
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings windows registry reading fails on certain keys

    Your virtual device is present into Device Manager?

  6. #6
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSettings windows registry reading fails on certain keys

    No it isn't listed there.

    Edit: to be fair, I'm not sure why that would be relevant. What if I wanted to read a completely different key starting with a "/"?
    Last edited by Kwakkie; 17th December 2012 at 11:01.

  7. #7
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings windows registry reading fails on certain keys

    No it isn't listed there.
    Then yes, you need to read the registry. Instead QSettings, try WinAPI I think it will be easier.

Similar Threads

  1. Replies: 4
    Last Post: 27th October 2011, 15:57
  2. QSettings and Windows registry - removing a key
    By lxman in forum Qt Programming
    Replies: 1
    Last Post: 29th July 2011, 20:43
  3. Replies: 1
    Last Post: 24th June 2011, 11:11
  4. reading windows registry
    By bhogasena in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2009, 09:36
  5. Replies: 1
    Last Post: 19th September 2008, 15:43

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.