Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to distinuguish between Fedora/centOS and Debian/Ubuntu OS in Qt5
Forum Update on Monday, May 27th 2025

How to distinuguish between Fedora/centOS and Debian/Ubuntu OS in Qt5

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 7 Posters 413 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ryna
    wrote on last edited by
    #1

    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.

    JonBJ raven-worxR 2 Replies Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #3

      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.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      R 1 Reply Last reply
      1
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #2

        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.

        1 Reply Last reply
        0
        • jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #3

          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.

          Asking a question about code? http://eel.is/iso-c++/testcase/

          R 1 Reply Last reply
          1
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #4

            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?

            R 1 Reply Last reply
            0
            • R Ryna

              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.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #5

              @Ryna
              Purely OOI, why do you need to distinguish between these distros? If, say, you want to run apt 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 via uname() (man 2 uname) as a system call from code.

              1 Reply Last reply
              0
              • R Ryna

                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-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by raven-worx
                #6

                @Ryna
                see QSysInfo class and inspect its properties

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                R 1 Reply Last reply
                0
                • raven-worxR raven-worx

                  @Ryna
                  see QSysInfo class and inspect its properties

                  R Offline
                  R Offline
                  Ryna
                  wrote on last edited by
                  #7

                  @raven-worx yes, I checked that. productVersion can help me. Thank you

                  1 Reply Last reply
                  0
                  • jeremy_kJ jeremy_k

                    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.

                    R Offline
                    R Offline
                    Ryna
                    wrote on last edited by
                    #8

                    @jeremy_k Thank you. Yes that has worked.

                    1 Reply Last reply
                    0
                    • JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by
                      #9

                      Try this env to see if it helps.
                      echo $DESKTOP_SESSION

                      1 Reply Last reply
                      0
                      • C ChrisW67

                        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?

                        R Offline
                        R Offline
                        Ryna
                        wrote on last edited by
                        #10

                        @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.

                        JonBJ 1 Reply Last reply
                        0
                        • R Ryna

                          @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.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #11

                          @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?

                          JoeCFDJ 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @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?

                            JoeCFDJ Offline
                            JoeCFDJ Offline
                            JoeCFD
                            wrote on last edited by
                            #12

                            @JonB what if it is not installed?

                            JonBJ 1 Reply Last reply
                            0
                            • JoeCFDJ JoeCFD

                              @JonB what if it is not installed?

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #13

                              @JoeCFD
                              First it would be pretty odd for a Deb not to have dpkg, 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.

                              R 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @JoeCFD
                                First it would be pretty odd for a Deb not to have dpkg, 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.

                                R Offline
                                R Offline
                                Ryna
                                wrote on last edited by
                                #14

                                @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.

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved