Results 1 to 17 of 17

Thread: How to read registry entries

  1. #1
    Join Date
    Jun 2008
    Posts
    22

    Default How to read registry entries

    I am calling an application built in C# from my Qt application. In the C# application I have some registry entires made. I want to read these entries in my Qt program and display certain messages depending on the value obtained. Please let me know how to do this.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to read registry entries

    See QSettings. Notice especially "Accessing the Windows Registry Directly" in the detailed description.
    J-P Nurmi

  3. #3
    Join Date
    Jun 2008
    Posts
    22

    Default Re: How to read registry entries

    I read about QSettings but I am still not able to do it.
    Can you please give a little more explanation about doing the same??

  4. #4
    Join Date
    May 2008
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4

    Default Re: How to read registry entries

    Hi,

    Use QSettings like this..

    QSettings settings;
    //setValue is to set the value to the registry.
    settings.setValue("somekey", ui.someButton->isChecked() );

    //value is to get the stored value from the registry..
    settings.value("somekey", true).toBool();

    All the best..

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to read registry entries

    search getGSDefaultExeName on file
    http://fop-miniscribus.googlecode.co...tpanelmime.cpp
    is part from http://www.qtcentre.org/forum/f-qt-p...=qtextdocument
    a small qtextedit display on paper format like word openoffice..


    here a small example to search on regedit on this case it search GhostScript by version....

    Qt Code:
    1. /* find gpl GhostScript path or exe */
    2. QString getGSDefaultExeName()
    3. {
    4. QString gsName;
    5. QString gVersion;
    6. #if defined Q_WS_WIN
    7. QFileInfo Pinfo;
    8. // Try to locate GhostScript thanks to the qsetting
    9. gsName = "gswin32c.exe";
    10. QSettings softs("HKEY_LOCAL_MACHINE\\Software",QSettings::NativeFormat);
    11. QStringList allsoftware = softs.childGroups();
    12. QStringList gsonly = allsoftware.filter(QRegExp("Ghostscript"));
    13. //////////qDebug() << "### gsonly " << gsonly;
    14. for (int i = 0; i < gsonly.size(); ++i)
    15. {
    16. const QString RealName = gsonly.at(i); /* realpath */
    17. if (RealName.contains("Ghostscript"))
    18. {
    19. //////////qDebug() << "### soft " << RealName;
    20. for (int e=1;e<99;e++)
    21. {
    22. /* check version 8 ++ 99 down */
    23. gVersion = QString("8.%1").arg(100 - e);
    24. if (softs.value(RealName+"/"+gVersion+"/GS_DLL").toString().size() > 6)
    25. {
    26. Pinfo.setFile(softs.value(RealName+"/"+gVersion+"/GS_DLL").toString());
    27. return gsName.prepend(Pinfo.absolutePath()+"/");
    28. }
    29. /* check version 7 ++ 99 down */
    30. gVersion = QString("7.%1").arg(100 - e);
    31. if (softs.value(RealName+"/"+gVersion+"/GS_DLL").toString().size() > 6)
    32. {
    33. Pinfo.setFile(softs.value(RealName+"/"+gVersion+"/GS_DLL").toString());
    34. return gsName.prepend(Pinfo.absolutePath()+"/");
    35. }
    36. }
    37. }
    38. }
    39.  
    40. /* win not having GPL Ghostscript ! */
    41. gsName = "";
    42. return gsName;
    43. #endif
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jun 2008
    Posts
    22

    Default Re: How to read registry entries

    I understood about QSettings but still not getting what I intend.

    I have a key named 'Status' which can take two values 'success' or 'failed' according to the process and is available in the path 'Software/Burn'. I want to display some message depending on the value obtained. I have done it like...

    Qt Code:
    1. QSettings settings("HKEY_CURRENT_USER/Software/Burn", QSettings::NativeFormat);
    2. QString value = settings.value("HKEY_CURRENT_USER/Software/Burn/Status").toString();
    3. if(value == "failed") {
    4. // display some message
    5. } else if(value == "success") {
    6. // display some message
    7. }
    To copy to clipboard, switch view to plain text mode 

    Please let me know what's wrong in this, why doesn't it work???
    Last edited by jpn; 21st August 2008 at 08:38. Reason: missing [code] tags

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to read registry entries

    Please follow the example in the docs. Your attempt is radically different. Notice what docs say about slashes and about registry entries appearing under the specified path.
    J-P Nurmi

  8. #8
    Join Date
    Jun 2008
    Posts
    22

    Default Re: How to read registry entries

    Still does not work for me...

    Did u mean that I should do something like...

    Qt Code:
    1. QSettings settings("HKEY_CURRENT_USER\\Software\\Burn", QSettings::NativeFormat);
    2. QString value = settings.value("Status").toString();
    3. if(value == "failed") {
    4. // display some message
    5. } else if(value == "success") {
    6. // display some other message
    7. }
    To copy to clipboard, switch view to plain text mode 

    Please tell me what's going wrong now.
    Last edited by jpn; 21st August 2008 at 10:45. Reason: missing [code] tags

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to read registry entries

    Could you export and paste contents of HKEY_CURRENT_USER\\Software\\Burn?
    J-P Nurmi

  10. #10
    Join Date
    Jun 2008
    Posts
    22

    Default Re: How to read registry entries

    The contents are as follows...

    (Default) REG_SZ (value not set)
    Status REG_SZ failed
    CommPort REG_DWORD 0x00000003(3)
    CommSpeed REG_DWORD 0x00000000(0)
    FileName REG_SZ C:/Documnets & Settings/.... (path to the file)

  11. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to read registry entries

    Is that really an export? As far as I remember it looks a bit different. I wanted to assure that the path is actually correct but I guess you've already done that. Anyway, what does
    Qt Code:
    1. qDebug() << settings.childKeys();
    2. qDebug() << settings.childGroups();
    To copy to clipboard, switch view to plain text mode 
    output?
    J-P Nurmi

  12. #12
    Join Date
    Jun 2008
    Posts
    22

    Default Re: How to read registry entries

    These two commands don't return any value...
    Now, how to proceed.

  13. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to read registry entries

    So are you 100% sure that the registry path is correct? Does this assert?
    Qt Code:
    1. QSettings settings("HKEY_CURRENT_USER", QSettings::NativeFormat);
    2. Q_ASSERT_X(settings.childGroups().contains("Software"), "Software", "Software doesn't exist");
    3. settings.beginGroup("Software");
    4.  
    5. Q_ASSERT_X(settings.childGroups().contains("Burn"), "Burn", "Burn doesn't exist");
    6. settings.beginGroup("Burn");
    7.  
    8. Q_ASSERT_X(!settings.allKeys().isEmpty(), "Keys", "Software/Burn is empty");
    9. qDebug() << settings.allKeys();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  14. #14
    Join Date
    Jun 2008
    Posts
    22

    Default Re: How to read registry entries

    If I include this snippet, I don't get any output.
    Infact, qDebug does not work for me I guess.

    Just don't know how to get this working...
    Last edited by Abc; 21st August 2008 at 14:25.

  15. #15
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to read registry entries

    You could have said that earlier when I asked for the output of childKeys() and childGroups(). In case you're using an IDE of some kind, check its output console. In case you're not, enable console by adding
    Qt Code:
    1. CONFIG += debug console
    To copy to clipboard, switch view to plain text mode 
    to the .pro file, re-run qmake, make clean and recompile the application. Now you should see some output in the console window.
    J-P Nurmi

  16. #16
    Join Date
    Jun 2008
    Posts
    22

    Default Re: How to read registry entries

    If I include this in the .pro file, the application does not build.

    I am writing Qt code in notepad++ and using Qt 4.4.0 Command Prompt to build my application.

    I did this... added the given line to .pro file, did a make clean and then qmake followed by a make.
    The error message reads like...
    C:\MinGW\bin\..\lib\gcc\ming32\3.4.5\..\..\..\..\m ingw32\bin\ld.exe: cannot find -lQtGuid4
    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [debug\myApplication.exe] Error 1
    mingw32-make[1]: Leaving directory '<path to the directory>'
    mingw32-make: *** [debug] Error 2

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to read registry entries

    You don't have Qt libraries built in debug mode. There should be a "Build Qt in debug mode" or similar link in start menu.

Similar Threads

  1. External Lib read from QBuffer on Calback problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2008, 19:43
  2. How to read CD with read?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 29th June 2007, 08:20
  3. QIODevice read()
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 00:29

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.