Results 1 to 8 of 8

Thread: Qt 4 Registry regedit

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Qt 4 Registry regedit

    Hey there trolls,

    I'd like to execute a windows registry command at my Qt program startup ?

    Anybody ever did that ?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt 4 Registry regedit

    Could you elaborate? A trivial solutions seems to be to read the command from the registry using QSettings and execute it using QDesktopServices. Or maybe I understood your problem incorrectly?

  3. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Qt 4 Registry regedit

    I want to run the equivalent for that .reg file:

    Windows Registry Editor Version 5.00
    [HKEY_CLASSES_ROOT\xmpp]
    @="URL:XMPP Protocol"
    "EditFlags"=dword:00000002
    "URL Protocol"=""
    [HKEY_CLASSES_ROOT\xmpp\shell]
    [HKEY_CLASSES_ROOT\xmpp\shell\open]
    [HKEY_CLASSES_ROOT\xmpp\shell\open\command]
    @="<application to execute> %l"

    I'm not sure if I do create the reg file and execute it, or if I can adopt a more straightforward approach.

    As you suggested, I'll take a look at QDesktopServices.

  4. #4
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4 Registry regedit

    Your intention is still a little vague.
    If what you mean is to apply the value in the .reg file as if you had double-clicked the file in Windows Explorer, you could could probably get away with QDesktopServices:penUrl, but another option is to use QSettings adding each value in c++ code.

    QSettings is an ini file and registry reader / writer.
    You could create a registry version of QSettings and call setValue specifying the hive key and value to insert.

    I'd say the QDesktopServices approach is preferable as you cold modify the .reg file easier.
    If you wanted to keep things in a text file and use QSettings, then for simplicity you'd need to re-arrange your reg into an ini file format, access the ini file with one QSettings object for reading the values, then use another QSettings object for writing to the registry.

  5. #5
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Qt 4 Registry regedit

    Qt Code:
    1. QDesktopServices::openUrl(QUrl::fromLocalFile("ZeMessenger.reg"))
    To copy to clipboard, switch view to plain text mode 

    Doesn't work.

    I need to execute a regedit file with every instance of my app.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt 4 Registry regedit

    Use system() with regedit.exe or QProcess with regedit.exe or insert the information into the registry using QSettings. And try expressing your goals more clearly next time - I though you wanted to do something completely different.

  7. #7
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Qt 4 Registry regedit

    Sorry if I didin't sound clear.

    Qt Code:
    1. QString program = "C:\\Windows\\regedit.exe";
    2. QStringList arguments;
    3. arguments << "/S" << "ZeMessenger.reg";
    4.  
    5. QProcess myProcess;
    6. myProcess.start(program, arguments);
    7.  
    8. if (!myProcess.waitForStarted())
    9. {
    10. return false;
    11. }
    To copy to clipboard, switch view to plain text mode 

    That code returns false. I'm affraid I need administrator rights to do such a command. I guess the only alternative to add regs field silently is during the installation.

  8. #8
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4 Registry regedit

    For starters, you don't actually need to launch regedit as the association for .reg is to open regedit, although that won't fix your problem.

    If you can't run .reg files, then chances are you won't be able to modify the registry keys even with QSettings. If this is a work machine that's locked down, then request permission to get your job done, otherwise if it's a personal machine, add yourself to the Administrators group.

Similar Threads

  1. Qt instruments for working with registry?
    By XL in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2008, 17:36
  2. reading from registry
    By phillip_Qt in forum Newbie
    Replies: 11
    Last Post: 26th October 2007, 06:49
  3. setting valeu through registry
    By sudhansu.kanungo in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2007, 20:55
  4. Accessing Windows Registry
    By musaulker in forum Newbie
    Replies: 1
    Last Post: 29th March 2007, 00:32
  5. [QSettings] Why limiting to plain file or registry ?
    By lauranger in forum Qt Programming
    Replies: 8
    Last Post: 13th September 2006, 14:25

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.