Important: Please read the 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?

  • Lifetime Qt Champion

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

  • @jsulm

    Whenever I run a function called A, I want to know if the computer has a Linux package installed.

  • Lifetime Qt Champion


    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.

  • Lifetime Qt Champion

    @Pada_ said in How to Determine if installed Library ??:

    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.

  • @jsulm

    I am going to do the following to determine if there is UNRAR on Linux.

    1. Enter terminal UNRAR with QProcess and execute.

    2. Would you get an error message without UNRAR?

    3. Receive the QProcess result and do not execute it in case of error.

    Is the method above correct?

  • @Pada_
    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 for this example.

    Beware, Linux is case-sensitive, I doubt it would be UNRAR, more likely unrar....

    unrar is not installed under Ubuntu at least. apt install offers unrar-free & unrar packages.

Log in to reply