How to distinuguish between Fedora/centOS and Debian/Ubuntu OS in Qt5
-
There might be a file /etc/os-release that contains sh style variable assignments. For example:
NAME="Ubuntu" VERSION="20.04.2 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.2 LTS" VERSION_ID="20.04" 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" VERSION_CODENAME=focal UBUNTU_CODENAME=focal
ID and VERSION_ID seem to exist reliably in the distros I've looked at (Ubuntu, Debian, Fedora, OpenSUSE, and vendor supported versions of these). There are lots of variables that are distribution-specific.
QSysInfo will use this file, at least in the version of the Qt source I'm looking at. QSysInfo::productType() might be a reasonable choice for this purpose.
-
There is no linux requirement for distros to identify themselves so any attempt will be ad-hoc. I'd suggest writing your app to be distro neutral.
-
There might be a file /etc/os-release that contains sh style variable assignments. For example:
NAME="Ubuntu" VERSION="20.04.2 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.2 LTS" VERSION_ID="20.04" 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" VERSION_CODENAME=focal UBUNTU_CODENAME=focal
ID and VERSION_ID seem to exist reliably in the distros I've looked at (Ubuntu, Debian, Fedora, OpenSUSE, and vendor supported versions of these). There are lots of variables that are distribution-specific.
QSysInfo will use this file, at least in the version of the Qt source I'm looking at. QSysInfo::productType() might be a reasonable choice for this purpose.
-
Jeremy_k has a run-time answer that may work.
Differentiating at compile time (i.e. with a macro) is not feasibly simply because the build machine and the run time machine are not the same.
@Ryna Why do you need to tell the two apart? What will you do differently?
-
@Ryna
Purely OOI, why do you need to distinguish between these distros? If, say, you want to runapt
under Debian I would just test whether/usr/bin/apt
is present,Otherwise
uname -a
gives what information is available. I presume you can access what you want from that viauname()
(man 2 uname) as a system call from code. -
-
@raven-worx yes, I checked that. productVersion can help me. Thank you
-
@JoeCFD
First it would be pretty odd for a Deb not to havedpkg
, so far as I know.The OP seems to want to run
dpkg
. If it's Deb but not available he can't run it, just like under Fed. I don't see what you gain by trying to look for some product type in this situation. Up to the OP. -
@JonB Packages which I am able to install on mint, same package I was unable to install on fedora. Looks like I need to take different version of package for both distros. Fedora and Mint versions are constant and can't be changed so I can pick up package based on this differentiation I guess.