【QML】Qt和QML获取操作系统类型

1. Qt获取系统类型

c 复制代码
//方法
QSysInfo::productType()

//举例:
if(QSysInfo::productType() == "windows")
{
	qDebug() << "windows system";
}

官方说明:

c 复制代码
[static] QString QSysInfo::productType()
Returns the product name of the operating system this application is running in. If the application is running on some sort of emulation or virtualization layer (such as WINE on a Unix system), this function will inspect the emulation / virtualization layer.
Values returned by this function are stable and will not change over time, so applications can rely on the returned value as an identifier, except that new OS types may be added over time.
Linux and Android note: this function returns "android" for Linux systems running Android userspace, notably when using the Bionic library. For all other Linux systems, regardless of C library being used, it tries to determine the distribution name and returns that. If determining the distribution name failed, it returns "unknown".
macOS note: this function returns "osx" for all macOS systems, regardless of Apple naming convention. The returned string will be updated for Qt 6. Note that this function erroneously returned "macos" for macOS 10.12 in Qt versions 5.6.2, 5.7.1, and 5.8.0.
Darwin, iOS, tvOS, and watchOS note: this function returns "ios" for iOS systems, "tvos" for tvOS systems, "watchos" for watchOS systems, and "darwin" in case the system could not be determined.
FreeBSD note: this function returns "debian" for Debian/kFreeBSD and "unknown" otherwise.
Windows note: this function "winrt" for WinRT builds, and "windows" for normal desktop builds.
For other Unix-type systems, this function usually returns "unknown".
This function was introduced in Qt 5.4.
See also QFileSelector, kernelType(), kernelVersion(), productVersion(), and prettyProductName().

2. QML获取系统类型

c 复制代码
//方法
Qt.platform.os

//举例
if(Qt.platform.os === "windows"){
            console.log("windows system")
        }else if(Qt.platform.os === "linux"){
            console.log("linux system")
        }

官方说明:

c 复制代码
platform : object

The platform object provides info about the underlying platform.
Its properties are:

platform.os
This read-only property contains the name of the operating system.
Possible values are:
	"android" - Android
	"ios" - iOS
	"tvos" - tvOS
	"linux" - Linux
	"osx" - macOS
	"qnx" - QNX (since Qt 5.9.3)
	"unix" - Other Unix-based OS
	"windows" - Windows
	"winrt" - WinRT / UWP
	"wasm" - WebAssembly
platform.pluginName
This is the name of the platform set on the QGuiApplication instance as returned by QGuiApplication::platformName()

This property was introduced in Qt 5.1.
相关推荐
liuyao_xianhui1 分钟前
优选算法_两数之和_位运算_C++
java·开发语言·数据结构·c++·算法·链表·动态规划
IT猿手13 分钟前
MATLAB模拟四旋翼无人机飞行,机翼可独立旋转
开发语言·matlab·无人机
代龙涛24 分钟前
WordPress 主题开发指南:模板文件、函数与页面选型规则
开发语言·后端·php·wordpress
代码探秘者24 分钟前
【大模型应用】6.RAG 场景下的向量+关键词混合检索
java·开发语言·人工智能·python·spring
RFCEO1 小时前
JavaScript基础课程十四、原型与原型链(JS 核心底层)
开发语言·原型模式·prototype原型详解·javascript基础课·构造函数原型方法定义与使用·js原型链继承机制入门·t原型链顶层null原理
liuyao_xianhui1 小时前
优选算法_位运算_只出现一次的数字3_C++
开发语言·数据结构·c++·算法·leetcode·链表·动态规划
Sylvia33.1 小时前
体育数据API实战:用火星数据实现NBA赛事实时比分与状态同步
java·linux·开发语言·前端·python
遗憾随她而去.1 小时前
js 插件 Clipboard.js 与原生 Clipboard API 全方位对比
开发语言·前端·javascript
人道领域1 小时前
Day | 07 【苍穹外卖 :用户端添加购物车】
java·开发语言·数据库·后端·苍穹外卖