How to get registry entries if there are multiple versions installed on Windows system using Qt API?
-
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
-
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, ...
-
You should enclose your code snippet in '@'. Otherwise it cannot be read.
-
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 -
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
-
Thank you :)
This code is working fine for me.