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?
-
Hi,
My application needs to support Linux (Ubuntu and Fedora). Which is the best way/MACRO to differentiate between Ubuntu and Fedora OS in Qt5?
Thanks for your help.@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. -
Hi,
My application needs to support Linux (Ubuntu and Fedora). Which is the best way/MACRO to differentiate between Ubuntu and Fedora OS in Qt5?
Thanks for your help. -
@raven-worx yes, I checked that. productVersion can help me. Thank you
-
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?
-
@ChrisW67 said in How to distinuguish between Fedora/centOS and Debian/Ubuntu OS in Qt5:
@Ryna Why do you need to tell the two apart? What will you do differently?
I need to use dpkg that needs me to distinguish between two distros.
-
@Ryna said in How to distinuguish between Fedora/centOS and Debian/Ubuntu OS in Qt5:
I need to use dpkg that needs me to distinguish between two distros.
So why not test for whether
dpkg
is present? -
@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. -
@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.