简体   繁体   English

如何在 QT5 中获取基于 Linux 的系统

[英]How to get Linux based system in QT5

I am developing an application on qt5 using c++ which will support all popular distros, for this currently I am using QSysInfo我正在使用 c++ 在 qt5 上开发一个应用程序,它将支持所有流行的发行版,为此我目前正在使用 QSysInfo

 qDebug() << "currentCpuArchitecture():" << QSysInfo::currentCpuArchitecture();
    qDebug() << "productType():" << QSysInfo::productType();
    qDebug() << "productVersion():" << QSysInfo::productVersion();
    qDebug() << "prettyProductName():" << QSysInfo::prettyProductName();

It returns ubuntu, manjaro... in prettyProductName, I actually need a base system like Debian, arch... Tia它返回 ubuntu,manjaro... 在 prettyProductName 中,我实际上需要一个像 Debian,arch... Tia 这样的基本系统

All Linux distros are just Linux so you need to read distro-specific values:所有 Linux 发行版都只是 Linux 因此您需要阅读发行版特定的值:

$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

The files are distro-specific and the information in those files are also distro-specific so the files and fields may differ from one distro to another.这些文件是特定于发行版的,并且这些文件中的信息也是特定于发行版的,因此文件和字段可能因发行版而异。 Some distro may not even have them有些发行版甚至可能没有它们

Similarly there's a common tool named lsb_release in most common distros and you can check its output if it exists同样,在大多数常见发行版中都有一个名为lsb_release的通用工具,如果存在,您可以检查其 output

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:    20.04
Codename:   focal

If a rare distro doesn't have any of those then probably you're out of luck如果一个稀有的发行版没有这些,那么你可能不走运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM