Results 1 to 5 of 5

Thread: check windows registry key existence

  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default check windows registry key existence

    Hi there! I'd like to know whether it is possible to find out if a registry key exists by the means of QSettings. I was trying to use QSettings::contains, but it doesn't work.

    Qt Code:
    1. QSettings reg("HKEY_LOCAL_MACHINE\\Software\\VideoLan", QSettings::NativeFormat);
    2. bool exists = reg.contains("VLC");
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: check windows registry key existence

    Could it be that "VLC" is a subkey and not a value? Does this work?

    Qt Code:
    1. QSettings reg("HKEY_LOCAL_MACHINE\\Software\\VideoLan\\VLC", QSettings::NativeFormat);
    2. bool exists = reg.contains("Default");
    To copy to clipboard, switch view to plain text mode 

    Joh

  3. #3
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: check windows registry key existence

    Yes, VLC is a subkey and not a value. But I thought QSettings::contains is intended to be used for keys. Your code works, but I can't check key the way you said, because actually I don't need registry keys to be created (QSettings will create key if "HKEY_LOCAL_MACHINE\\Software\\VideoLan\\VLC" doesn't exist), therefore I need to use somethings like:
    Qt Code:
    1. QSettings reg("HKEY_LOCAL_MACHINE", QSettings::NativeFormat);
    2. bool exists = reg.contains("Software\\VideoLan\\VLC");
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QSettings reg("HKEY_LOCAL_MACHINE", QSettings::NativeFormat);
    2. bool exists = reg.contains("Software\\VideoLan\\VLC\\Default");
    To copy to clipboard, switch view to plain text mode 
    Or I don't know how to do it in a better way. But anyway this doesn't work.

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: check windows registry key existence

    Well no idea. As this is highly platform dependent anyway, why don't you use winapi directly?

    Qt Code:
    1. #ifdef Q_OS_WIN
    2. #include "windows.h"
    3. #endif
    4.  
    5. bool existsAndSuccess = false;
    6. #ifdef Q_OS_WIN
    7. HKEY hKey;
    8. existsAndSuccess = (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\VideoLan\\VLC", 0, KEY_READ, &hKey) == ERROR_SUCCESS);
    9. #endif
    10. qDebug() << existsAndSuccess;
    To copy to clipboard, switch view to plain text mode 
    Maybe somebody else knows how to do this with QSettings properly?

    Joh

  5. #5
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: check windows registry key existence

    yes, i ended up with this approach. but later i use qsettings anyway (because it is easier), therefore i thought to use qsettings for this check also and, generally, i was interested whether it is possible. ok, thank you.

Similar Threads

  1. check IPAddress existence
    By navi1084 in forum Qt Programming
    Replies: 8
    Last Post: 16th May 2013, 21:26
  2. Test for existence of SQLite db
    By scott_hollen in forum Newbie
    Replies: 4
    Last Post: 3rd February 2011, 06:14
  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. Accessing Windows Registry
    By musaulker in forum Newbie
    Replies: 1
    Last Post: 29th March 2007, 00:32

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.