Qt World Summit: Register Today!

check if a application is installed

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

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

  • @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)

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

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


  • @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");

  • @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)


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

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


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

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

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

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

Log in to reply