Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get registry entries if there are multiple versions installed on Windows system using Qt API?
Forum Updated to NodeBB v4.3 + New Features

How to get registry entries if there are multiple versions installed on Windows system using Qt API?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    prbiswal
    wrote on last edited by
    #1

    I have multiple NetBeans installed on my windows machine. the registry entries are under:

    7.0 version is under: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\nbi-nb-base-7.0.0.0.0

    6.5 version is under: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\nbi-nb-base-6.5.0.0.200811100001

    My requirement is to get the latest version of installed NetBeans from registry entry table using Qt APIs. Please let me know if any body has done this and share the sample code.

    I am able to get the registry entries of netbeans using QSettings api as below:

    @
    QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\nbi-nb-base-7.0.0.0.0"), QSettings::NativeFormat);
    QString netBeansPath = settings.value(QLatin1String("InstallLocation"),0).toString();
    @

    but dont know how to get all installed netbeans IDEs and choose the latest version.

    Regards, Pr

    Regards,
    Pradeep

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      This is no Qt related issue.
      You can access the registry with QSettings, but how to check, which is the latest version...
      I would iterate all child elements of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall and check with a reg exp ´which versions are there.

      Just split this: nbi-nb-base-7.0.0.0.0 into a reg exp in name, maj version, minor version, ...

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        You should enclose your code snippet in '@'. Otherwise it cannot be read.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • P Offline
          P Offline
          prbiswal
          wrote on last edited by
          #4

          Thanks Gerolf,

          How to iterate all child members under HKEY_LOCAL_MACHINE..\Uninstall ?
          Not getting idea to list out all installed NetBeans in reg (nbi-nb-base- )?
          if i will get all reg entries then i get values for "DisplayVersion" and can compare to get the latest version.

          Could you please share some code snippet how to do it?

          Regards,
          Pr

          Regards,
          Pradeep

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            you can use "QSettings::childGroups":http://doc.qt.nokia.com/4.7/qsettings.html#childGroups which would result in something like this:

            @
            class MyVersion
            {
            MyVersion(int nMajor, int nMinor, int nServicePack, int nHotFix)
            m_nMajor(nMajor),
            m_nMinor(nMinor),
            m_nServicePack(nServicePack),
            m_nHotFix(nHotFix)
            {
            }

            bool operator==(const MyVersion& rCompare)
            {
                if(m_nMajor != nMajor) return false;
                if(m_nMinor != nMinor) return false;
                if(m_nServicePack != nServicePack) return false;
                if(m_nHotFix != nHotFix) return false;
                return true;
            }
            
            bool operator!=(const MyVersion& rCompare)
            {
                return !operator==(rCompare);
            }
            
            bool operator<(const MyVersion& rCompare)
            {
                if(m_nMajor < nMajor) return true;
                if(m_nMajor > nMajor) return false;
                if(m_nMinor < nMinor) return true;
                if(m_nMinor > nMinor) return false;
                if(m_nServicePack < nServicePack) return true;
                if(m_nServicePack > nServicePack) return false;
                if(m_nHotFix < nHotFix) return true;
                if(m_nHotFix > nHotFix) return false;
                return false;
            }
            
            bool operator>(const MyVersion& rCompare)
            {
                if(m_nMajor > nMajor) return true;
                if(m_nMajor < nMajor) return false;
                if(m_nMinor > nMinor) return true;
                if(m_nMinor < nMinor) return false;
                if(m_nServicePack > nServicePack) return true;
                if(m_nServicePack < nServicePack) return false;
                if(m_nHotFix > nHotFix) return true;
                if(m_nHotFix < nHotFix) return false;
                return false;
            }
            
            int m_nMajor;
            int m_nMinor;
            int m_nServicePack;
            int m_nHotFix;
            

            }

            QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"), QSettings::NativeFormat);
            QStringList groups = settings.childGroups();
            QString newestVersion;
            MyVersion currentVersion(0,0,0,0);

            for(QStringList::iterator it = groups.begin(); it != groups.end(); ++it)
            {
            QRegExp regExp("^nbi-nb-base-(\d+)\.(\d+)\.(\d+)\.(\d+)\..*$");

            if(regExp.exactMath(*it))
            {
                MyVersion thisVersion(regExp.cap(1).toInt(), regExp.cap(2).toInt(), regExp.cap(3).toInt(), regExp.cap(4).toInt());
                
                if(thisVersion > currentVersion)
                {
                    newestVersion = *it;
                }
            }
            

            }

            if(!newestVersion.Empty())
            {
            settings.beginGroup(newestVersion);
            QString netBeansPath = settings.value(QLatin1String("InstallLocation"),0).toString();
            // do your stuff here
            settings.endGroup();
            }
            @

            The code is just hacked directly here, it is not compiled nor tested

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • P Offline
              P Offline
              prbiswal
              wrote on last edited by
              #6

              Thank you :)
              This code is working fine for me.

              Regards,
              Pradeep

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved