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. check if a application is installed

check if a application is installed

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 3.1k 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.
  • S Offline
    S Offline
    saber
    wrote on last edited by saber
    #1

    i am in linux .
    i want to know if a (mediainfo ) package is installed in system.

    how can i check if package is installed by qmake and by function??

    JonBJ 1 Reply Last reply
    0
    • S saber

      i am in linux .
      i want to know if a (mediainfo ) package is installed in system.

      how can i check if package is installed by qmake and by function??

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

      @saber
      So far as I know, there is no "simple" test for this under Linux.

      You could run an OS command (QProcess) of some kind of apt-get/apt/dpkg and parse the output (not necessarily portable across various Linux flavors), or be lazy and just check for some file existence somewhere (again, may not be portable/reliable).

      S 1 Reply Last reply
      2
      • JonBJ JonB

        @saber
        So far as I know, there is no "simple" test for this under Linux.

        You could run an OS command (QProcess) of some kind of apt-get/apt/dpkg and parse the output (not necessarily portable across various Linux flavors), or be lazy and just check for some file existence somewhere (again, may not be portable/reliable).

        S Offline
        S Offline
        saber
        wrote on last edited by saber
        #3

        @JonB anyway to check a package from qmake??

        like this cmake of pcmanfm file manger github

        this lines

        find_package(fm-qt REQUIRED)
        find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
        
        JonBJ 1 Reply Last reply
        0
        • S saber

          @JonB anyway to check a package from qmake??

          like this cmake of pcmanfm file manger github

          this lines

          find_package(fm-qt REQUIRED)
          find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @saber
          Sorry, I don't use qmake, so I don't know if it can run a command/act on a return result....

          JonBJ 1 Reply Last reply
          0
          • Paul ColbyP Offline
            Paul ColbyP Offline
            Paul Colby
            wrote on last edited by
            #5

            Hi @saber,

            If mediainfo is a library, as defined by the pkg-config Linux command then you can use QMake's built-in packagesExist() test function (it uses pkg-config internally). However, for non-library packages, you will need to use OS-dependant tools such as dpkg for Debian-based distros, and rpm for RHEL/Fedora based distros, etc.

            For example:

            system(dpkg -l mediainfo > /dev/null) {
                message(mediainfo package exists)
            }
            

            You can wrap that up in your own test function pretty easily, and add Linux distro detection if necessary.

            Cheers.

            1 Reply Last reply
            3
            • JonBJ JonB

              @saber
              Sorry, I don't use qmake, so I don't know if it can run a command/act on a return result....

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

              @JonB
              To clarify @Paul-Colby 's code suggestion, you need to test the returns result for zero to imply package existence, e.g.:

              if (system("dpkg -l mediainfo > /dev/null 2>&1") == 0) {
                  message("mediainfo package exists");
              }
              
              1 Reply Last reply
              0
              • Paul ColbyP Offline
                Paul ColbyP Offline
                Paul Colby
                wrote on last edited by
                #7

                @JonB said in check if a application is installed:

                you need to test the returns result for zero

                Ah, no you don't ;)

                Consider this sample:

                system(dpkg -l nano > /dev/null) {
                    message(nano exists)
                }
                
                !system(dpkg -l nano > /dev/null) {
                    message(nano does not exist)
                }
                
                system(dpkg -l mediainfo > /dev/null) {
                    message(mediainfo exists)
                }
                
                !system(dpkg -l mediainfo > /dev/null) {
                    message(mediainfo does not exist)
                }
                

                Output:

                Project MESSAGE: nano exists
                ...
                Project MESSAGE: mediainfo does not exist
                

                Whis is correct (I have nano installed, but not mediainfo).

                Cheers.

                S JonBJ 2 Replies Last reply
                3
                • Paul ColbyP Paul Colby

                  @JonB said in check if a application is installed:

                  you need to test the returns result for zero

                  Ah, no you don't ;)

                  Consider this sample:

                  system(dpkg -l nano > /dev/null) {
                      message(nano exists)
                  }
                  
                  !system(dpkg -l nano > /dev/null) {
                      message(nano does not exist)
                  }
                  
                  system(dpkg -l mediainfo > /dev/null) {
                      message(mediainfo exists)
                  }
                  
                  !system(dpkg -l mediainfo > /dev/null) {
                      message(mediainfo does not exist)
                  }
                  

                  Output:

                  Project MESSAGE: nano exists
                  ...
                  Project MESSAGE: mediainfo does not exist
                  

                  Whis is correct (I have nano installed, but not mediainfo).

                  Cheers.

                  S Offline
                  S Offline
                  saber
                  wrote on last edited by saber
                  #8

                  @Paul-Colby
                  thanks for the code.i am in arch.

                  what to #include for system??

                  and my app will run in different ditro so any other way that works on universally??

                  JonBJ 1 Reply Last reply
                  0
                  • Paul ColbyP Paul Colby

                    @JonB said in check if a application is installed:

                    you need to test the returns result for zero

                    Ah, no you don't ;)

                    Consider this sample:

                    system(dpkg -l nano > /dev/null) {
                        message(nano exists)
                    }
                    
                    !system(dpkg -l nano > /dev/null) {
                        message(nano does not exist)
                    }
                    
                    system(dpkg -l mediainfo > /dev/null) {
                        message(mediainfo exists)
                    }
                    
                    !system(dpkg -l mediainfo > /dev/null) {
                        message(mediainfo does not exist)
                    }
                    

                    Output:

                    Project MESSAGE: nano exists
                    ...
                    Project MESSAGE: mediainfo does not exist
                    

                    Whis is correct (I have nano installed, but not mediainfo).

                    Cheers.

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

                    @Paul-Colby
                    Sorry, I am talking about the C system call system(), in C++ code for his "function" in runtime code. Are you perchance talking about something in cmake, which i know nothing about? I think we are talking about different things.

                    1 Reply Last reply
                    0
                    • S saber

                      @Paul-Colby
                      thanks for the code.i am in arch.

                      what to #include for system??

                      and my app will run in different ditro so any other way that works on universally??

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

                      @saber

                      and my app will run in different ditro so any other way that works on universally??

                      As I said, there is nothing that will work universally across any Linux, since there is no real definition of a "package"/"application". (I am talking about your app's runtime code, I know nothing about cmake). For code for C's system() call, #include <stdlib.h>. Or you can do it via Qt's QProcess.

                      FlotisableF 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @saber

                        and my app will run in different ditro so any other way that works on universally??

                        As I said, there is nothing that will work universally across any Linux, since there is no real definition of a "package"/"application". (I am talking about your app's runtime code, I know nothing about cmake). For code for C's system() call, #include <stdlib.h>. Or you can do it via Qt's QProcess.

                        FlotisableF Offline
                        FlotisableF Offline
                        Flotisable
                        wrote on last edited by
                        #11

                        @JonB
                        I think @Paul-Colby is talking about qmake.

                        the qmake scope syntax and qmake build in test function system()

                        JonBJ 1 Reply Last reply
                        0
                        • FlotisableF Flotisable

                          @JonB
                          I think @Paul-Colby is talking about qmake.

                          the qmake scope syntax and qmake build in test function system()

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

                          @Flotisable
                          Yes, I came to realise that. I was answering the OP's "and by function", which I took to mean in his app's code.

                          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