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

46 篇文章 0 订阅

1. Qt获取系统类型

//方法1
QSysInfo::productType()

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

//方法2
QSysInfo::kernelType()

官方说明:

[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获取系统类型

//方法
Qt.platform.os

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

官方说明:

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.

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值