QString Helper::osVersion(){#ifdef Q_OS_LINUX utsname buf; if(!uname(&buf)) return QString("GNU/") + buf.sysname + " (Linux " + buf.release + ")"; else return "GNU/Linux";#else #ifdef Q_OS_MAC switch(QSysInfo::MacintoshVersion) { case QSysInfo::MV_CHEETAH : return "MacOS 10.0(Cheetah)"; case QSysInfo::MV_PUMA : return "MacOS 10.1(Puma)"; case QSysInfo::MV_JAGUAR : return "MacOS 10.2(Jaguar)"; case QSysInfo::MV_PANTHER : return "MacOS 10.3(Panther)"; case QSysInfo::MV_TIGER : return "MacOS 10.4(Tiger)"; case QSysInfo::MV_LEOPARD : return "MacOS 10.5(Leopard)"; case QSysInfo::MV_Unknown : return "MacOS(unknown)"; default : return "MacOS(unknown)"; } #else #ifdef Q_OS_WIN switch(QSysInfo::WindowsVersion) { case QSysInfo::WV_32s : return "Windows 3.1 with Win32s"; case QSysInfo::WV_95 : return "Windows 95"; case QSysInfo::WV_98 : return "Windows 98"; case QSysInfo::WV_Me : return "Windows Me"; case QSysInfo::WV_NT : return "Windows NT"; case QSysInfo::WV_2000 : return "Windows 2000"; case QSysInfo::WV_XP : return "Windows XP"; case QSysInfo::WV_2003 : return "Windows Server 2003"; case QSysInfo::WV_VISTA : return "Windows Vista"; case QSysInfo::WV_CE : return "Windows CE"; case QSysInfo::WV_CENET : return "Windows CE .NET"; default : return "Windows(unknown)"; } #else return "Unknown"; #endif #endif#endif}
QString osVersion(){ static QString osVersion; if(osVersion.isEmpty()) {#if defined(Q_OS_LINUX) utsname buf; if(uname(&buf) != -1) { osVersion.append(buf.release).append(QLatin1Char(' ')); osVersion.append(buf.sysname).append(QLatin1Char(' ')); osVersion.append(buf.machine).append(QLatin1Char(' ')); osVersion.append(QLatin1String(" (")).append(buf.machine).append(QLatin1Char(')')); } else { osVersion = QLatin1String("Linux(unknown)"); }#elif defined(Q_OS_MAC) switch(QSysInfo::MacintoshVersion) { case QSysInfo::MV_LEOPARD: osVersion = QLatin1String("MacOS 10.5(Leopard)"); break; case QSysInfo::MV_TIGER: osVersion = QLatin1String("MacOS 10.4(Tiger)"); break; case QSysInfo::MV_PANTHER: osVersion = QLatin1String("MacOS 10.3(Panther)"); break; case QSysInfo::MV_JAGUAR: osVersion = QLatin1String("MacOS 10.2(Jaguar)"); break; case QSysInfo::MV_PUMA: osVersion = QLatin1String("MacOS 10.1(Puma)"); break; case QSysInfo::MV_CHEETAH: osVersion = QLatin1String("MacOS 10.0(Cheetah)"); break; case QSysInfo::MV_9: osVersion = QLatin1String("MacOS 9"); break; case QSysInfo::MV_Unknown: default: osVersion = QLatin1String("MacOS(unknown)"); break; }#elif defined(Q_OS_WIN) switch(QSysInfo::WindowsVersion) { case QSysInfo::WV_CE_6: osVersion = QLatin1String("Windows CE 6.x"); break; case QSysInfo::WV_CE_5: osVersion = QLatin1String("Windows CE 5.x"); break; case QSysInfo::WV_CENET: osVersion = QLatin1String("Windows CE .NET"); break; case QSysInfo::WV_CE: osVersion = QLatin1String("Windows CE"); break; case QSysInfo::WV_VISTA: osVersion = QLatin1String("Windows Vista"); break; case QSysInfo::WV_2003: osVersion = QLatin1String("Windows Server 2003"); break; case QSysInfo::WV_XP: osVersion = QLatin1String("Windows XP"); break; case QSysInfo::WV_2000: osVersion = QLatin1String("Windows 2000"); break; case QSysInfo::WV_NT: osVersion = QLatin1String("Windows NT"); break; case QSysInfo::WV_Me: osVersion = QLatin1String("Windows Me"); break; case QSysInfo::WV_98: osVersion = QLatin1String("Windows 98"); break; case QSysInfo::WV_95: osVersion = QLatin1String("Windows 95"); break; case QSysInfo::WV_32s: osVersion = QLatin1String("Windows 3.1 with Win32s"); break; default: osVersion = QLatin1String("Windows(unknown)"); break; } if(QSysInfo::WindowsVersion & QSysInfo::WV_CE_based) osVersion.append(QLatin1String(" (CE-based)")); else if(QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) osVersion.append(QLatin1String(" (NT-based)")); else if(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) osVersion.append(QLatin1String(" (MS-DOS-based)"));#else return QLatin1String("Unknown");#endif } return osVersion;}
#uname -aSunOS hasname 5.10 Generic_127111-11 sun4u sparc SUNW,Sun-Fire-V490
QString osVersion(){ static QString osVersion; if(osVersion.isEmpty()) {#if defined(Q_OS_MAC) switch(QSysInfo::MacintoshVersion) { case QSysInfo::MV_LEOPARD: osVersion = QLatin1String("MacOS 10.5(Leopard)"); break; case QSysInfo::MV_TIGER: osVersion = QLatin1String("MacOS 10.4(Tiger)"); break; case QSysInfo::MV_PANTHER: osVersion = QLatin1String("MacOS 10.3(Panther)"); break; case QSysInfo::MV_JAGUAR: osVersion = QLatin1String("MacOS 10.2(Jaguar)"); break; case QSysInfo::MV_PUMA: osVersion = QLatin1String("MacOS 10.1(Puma)"); break; case QSysInfo::MV_CHEETAH: osVersion = QLatin1String("MacOS 10.0(Cheetah)"); break; case QSysInfo::MV_9: osVersion = QLatin1String("MacOS 9"); break; case QSysInfo::MV_Unknown: default: osVersion = QLatin1String("MacOS(unknown)"); break; }#elif defined(Q_OS_UNIX) utsname buf; if(uname(&buf) != -1) { osVersion.append(buf.release).append(QLatin1Char(' ')); osVersion.append(buf.sysname).append(QLatin1Char(' ')); osVersion.append(buf.machine).append(QLatin1Char(' ')); osVersion.append(QLatin1String(" (")).append(buf.machine).append(QLatin1Char(')')); } else { osVersion = QLatin1String("Linux/Unix(unknown)"); }#elif defined(Q_WS_WIN) || defined(Q_OS_CYGWIN) switch(QSysInfo::WindowsVersion) { case QSysInfo::WV_CE_6: osVersion = QLatin1String("Windows CE 6.x"); break; case QSysInfo::WV_CE_5: osVersion = QLatin1String("Windows CE 5.x"); break; case QSysInfo::WV_CENET: osVersion = QLatin1String("Windows CE .NET"); break; case QSysInfo::WV_CE: osVersion = QLatin1String("Windows CE"); break; case QSysInfo::WV_VISTA: osVersion = QLatin1String("Windows Vista"); break; case QSysInfo::WV_2003: osVersion = QLatin1String("Windows Server 2003"); break; case QSysInfo::WV_XP: osVersion = QLatin1String("Windows XP"); break; case QSysInfo::WV_2000: osVersion = QLatin1String("Windows 2000"); break; case QSysInfo::WV_NT: osVersion = QLatin1String("Windows NT"); break; case QSysInfo::WV_Me: osVersion = QLatin1String("Windows Me"); break; case QSysInfo::WV_98: osVersion = QLatin1String("Windows 98"); break; case QSysInfo::WV_95: osVersion = QLatin1String("Windows 95"); break; case QSysInfo::WV_32s: osVersion = QLatin1String("Windows 3.1 with Win32s"); break; default: osVersion = QLatin1String("Windows(unknown)"); break; } if(QSysInfo::WindowsVersion & QSysInfo::WV_CE_based) osVersion.append(QLatin1String(" (CE-based)")); else if(QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) osVersion.append(QLatin1String(" (NT-based)")); else if(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) osVersion.append(QLatin1String(" (MS-DOS-based)"));#else return QLatin1String("Unknown");#endif } return osVersion;}