#include <stdio.h>
/*!
@brief Returns one component of the OS version
@param component 1=major, 2=minor, 3=bugfix
*/
int GetOSVersionComponent(int component) {
char cmd[64] ;
sprintf(
cmd,
"sw_vers -productVersion | awk -F '.' '{print $%d}'",
component
) ;
FILE* stdoutFile = popen(cmd, "r") ;
int answer = 0 ;
if (stdoutFile) {
char buff[16] ;
char *stdout = fgets(buff, sizeof(buff), stdoutFile) ;
pclose(stdoutFile) ;
sscanf(stdout, "%d", &answer) ;
}
return answer ;
}
QString GetOSVersion()
{
QString qsVersion = QString::number(GetOSVersionComponent(1)) + "."\
+ QString::number(GetOSVersionComponent(2)) + "."\
+ QString::number(GetOSVersionComponent(3));
return qsVersion;
}