Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to Determine if installed Library ??
I am using Linux 64 Bit + Qt 5.4.
Qt program tries to extract the zip or rar archive.
In the Linux environment, a library package called unrar must be installed.
Before unpacking, I want to check if the unrar library package is installed on the user's computer.
Is there a function to find the library or a function to judge?
@Pada_ Usually you link against the lib and it is loaded together with your app when it starts. Or do you want to load the lib dynamically?
Whenever I run a function called A, I want to know if the computer has a Linux package installed.
Are you running the application using QProcess or are you using the library directly in your application ?
In the first case, QProcess will return an error so you can use that in the second case, your application will not start because it can find the dependencies.
Depending on how your distribute your package, you should already have whatever package you need as a dependency of your application so it triggers its installation when you install your package.
I want to know if the computer has a Linux package installed
Well, then take a look at apt-get, rpm and what else is there (there are many package managesr on Linux).
But I still don't understand your use case/problem: if you want unpack a file in your app then simply link your app against a lib which supports that file format and then distribute that lib with your binaries.
I am going to do the following to determine if there is UNRAR on Linux.
Enter terminal UNRAR with QProcess and execute.
Would you get an error message without UNRAR?
Receive the QProcess result and do not execute it in case of error.
Is the method above correct?
JonB last edited by JonB
I don't know what you mean/intend with your use of the word "terminal" here. You don't want any terminal to be involved.
There are several ways of testing for it. Here's a simple start:
int result = QProcess::execute("unrar", ); if (result == -2) qDebug() << "Could not start process";
See https://doc.qt.io/qt-5/qprocess.html#execute for this example.
Beware, Linux is case-sensitive, I doubt it would be
UNRAR, more likely
unraris not installed under Ubuntu at least.