Unsolved 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 ofapt-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). -
-
@saber
Sorry, I don't useqmake
, 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 thepkg-config
Linux command then you can use QMake's built-in packagesExist() test function (it usespkg-config
internally). However, for non-library packages, you will need to use OS-dependant tools such asdpkg
for Debian-based distros, andrpm
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.
-
@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) }
Output:
Project MESSAGE: nano exists ... Project MESSAGE: mediainfo does not exist
Whis is correct (I have
nano
installed, but notmediainfo
).Cheers.
-
@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 callsystem()
, in C++ code for his "function" in runtime code. Are you perchance talking about something incmake
, which i know nothing about? I think we are talking about different things. -
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'ssystem()
call,#include <stdlib.h>
. Or you can do it via Qt'sQProcess
. -
@JonB
I think @Paul-Colby is talking aboutqmake
.the qmake scope syntax and qmake build in test function system()
-
@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.