- class QOperatingSystemVersion#
该
QOperatingSystemVersion
类提供了有关操作系统版本的信息。 更多…注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对该片段翻译的贡献。如果您发现翻译有问题,您也可以通过在https:/bugreports.qt.io/projects/PYSIDE上创建工单来通知我们
详细描述#
警告
本节包含从C++自动翻译到Python的代码片段,可能包含错误。
与
QSysInfo
中的其他版本函数不同,QOperatingSystemVersion
提供了对完整版本号的访问,开发人员通常使用该版本号来改变行为或确定是否根据操作系统版本启用API或功能(而不是内核版本号或营销版本)。目前,支持Android、Apple平台(iOS、macOS、tvOS和watchOS)和Windows。
函数
majorVersion()
、minorVersion()
和microVersion()
返回基于操作系统的版本号的部分平台
值
Android
使用
QVersionNumber
解析android.os.Build.VERSION.RELEASE的结果,如果失败则回退到android.os.Build.VERSION.SDK_INT以确定主要和次要版本组件Apple平台
majorVersion
,minorVersion
和patchVersion
来自NSProcessInfo.operatingSystemVersionWindows
从RtlGetVersion获取dwMajorVersion、dwMinorVersion和dwBuildNumber - 注意,此函数始终返回底层数字系统的版本号,与GetVersionEx的(rawValue)函数不同,后者即使应用程序未针对该OS版本进行显式,也会隐藏真实版本号
由于
QOperatingSystemVersion
存储了版本号和操作系统类型,因此在执行比较时可以考虑操作系统类型。例如,在运行macOS Sierra (v10.12)的macOS系统上,以下表达式将返回false
,尽管表达式左侧对象的主体版本号组件(10)大于右侧对象的主体版本号(9)QOperatingSystemVersion.current() >= QOperatingSystemVersion(QOperatingSystemVersion.IOS, 9)
这允许使用逻辑OR运算符将多个操作系统的表达式组合在一起,并仍然按预期工作。例如
current = QOperatingSystemVersion.current() if (current >= QOperatingSystemVersion.OSXYosemite or current >= QOperatingSystemVersion(QOperatingSystemVersion.IOS, 8)) { # returns true on macOS >= 10.10 and iOS >= 8.0, but false on macOS < 10.10 and iOS < 8.0
一个更简单的比较算法可能会错误地返回所有版本的macOS(包括Mac OS 9)都为true。这种行为是通过重载比较运算符,使其在比较的
QOperatingSystemVersion
实例的操作系统类型不匹配时返回false
来实现的。请注意,由于这一点,对于相同的x
和y
实例,x
>= y 和x
< y 都可能为false
。- PySide6.QtCore.QOperatingSystemVersion.Windows7#
- PySide6.QtCore.QOperatingSystemVersion.Windows8#
- PySide6.QtCore.QOperatingSystemVersion.Windows8_1#
- PySide6.QtCore.QOperatingSystemVersion.Windows10#
- PySide6.QtCore.QOperatingSystemVersion.OSXMavericks#
- PySide6.QtCore.QOperatingSystemVersion.OSXYosemite#
- PySide6.QtCore.QOperatingSystemVersion.OSXElCapitan#
- PySide6.QtCore.QOperatingSystemVersion.MacOSSierra#
- PySide6.QtCore.QOperatingSystemVersion.MacOSHighSierra#
- PySide6.QtCore.QOperatingSystemVersion.MacOSMojave#
- PySide6.QtCore.QOperatingSystemVersion.MacOSCatalina#
- PySide6.QtCore.QOperatingSystemVersion.MacOSBigSur#
- PySide6.QtCore.QOperatingSystemVersion.MacOSMonterey#
- PySide6.QtCore.QOperatingSystemVersion.AndroidJellyBean#
- PySide6.QtCore.QOperatingSystemVersion.AndroidJellyBean_MR1#
- PySide6.QtCore.QOperatingSystemVersion.AndroidJellyBean_MR2#
- PySide6.QtCore.QOperatingSystemVersion.AndroidKitKat#
- PySide6.QtCore.QOperatingSystemVersion.AndroidLollipop#
- PySide6.QtCore.QOperatingSystemVersion.AndroidLollipop_MR1#
- PySide6.QtCore.QOperatingSystemVersion.AndroidMarshmallow#
- PySide6.QtCore.QOperatingSystemVersion.AndroidNougat#
- PySide6.QtCore.QOperatingSystemVersion.AndroidNougat_MR1#
- PySide6.QtCore.QOperatingSystemVersion.AndroidOreo#
- PySide6.QtCore.QOperatingSystemVersion.AndroidOreo_MR1#
- PySide6.QtCore.QOperatingSystemVersion.AndroidPie#
- PySide6.QtCore.QOperatingSystemVersion.Android10#
- PySide6.QtCore.QOperatingSystemVersion.Android11#
- PySide6.QtCore.QOperatingSystemVersion.Windows10_1809#
- PySide6.QtCore.QOperatingSystemVersion.Windows10_1903#
- PySide6.QtCore.QOperatingSystemVersion.Windows10_1909#
- PySide6.QtCore.QOperatingSystemVersion.Windows10_2004#
- PySide6.QtCore.QOperatingSystemVersion.Windows10_20H2#
- PySide6.QtCore.QOperatingSystemVersion.Windows10_21H1#
- PySide6.QtCore.QOperatingSystemVersion.Windows10_21H2#
- PySide6.QtCore.QOperatingSystemVersion.Windows10_22H2#
- PySide6.QtCore.QOperatingSystemVersion.Windows11#
- PySide6.QtCore.QOperatingSystemVersion.Windows11_21H2#
- PySide6.QtCore.QOperatingSystemVersion.Windows11_22H2#
- PySide6.QtCore.QOperatingSystemVersion.Android12#
- PySide6.QtCore.QOperatingSystemVersion.Android12L#
- PySide6.QtCore.QOperatingSystemVersion.Android13#
- PySide6.QtCore.QOperatingSystemVersion.MacOSVentura#