简体   繁体   中英

Deploying Qt applications in Linux properly

I have written an application using Qt and I am trying to deploy it. I built my application it and tried distributing it, but I ended up having to build Qt statically so that users don't need to install Qt's libraries just to run my application. The only problem is that the fonts are broken, and images don't load.

To statically build Qt, I did this:

./configure -static -release -ltcg -optimize-size -no-pch -prefix "/home/myuser/Qt/5.11.1-static" -skip webengine -nomake tools -nomake tests -nomake examples -fontconfig
make -j4
make -j4 install

There was then the issue of fonts not working. I kept getting the error "QFontDatabase: Cannot find font directory (Qt install directory)/libs/fonts", so I copied the dejavu fonts folder on my system to a folder called "fonts" in my program's directory and created a Bash script that set QT_QPA_FONTDIR to the new font directory. This made the error go away and made the text on my application visible, but when a password is being entered blank characters are displayed instead of asteriks or any other characters. Additionally, images do not show. I have a folder in the same directory as the application called "images" with my images inside, so I did this:

QIcon home("(program directory)/images/home.svg");
QIcon vpn("./images/vpn.svg");
ui->tabWidget->setTabIcon(0, home);
ui->tabWidget->setTabIcon(1, vpn);

The images do not show, but they do if the program is built using dynamic Qt. I tried both the full path and using ./ to refer to the current directory, but neither one results in the image appearing.

FWIW, the way my company packages the Linux build of its Qt app is with the dynamic libraries, as shown in the attached screenshot. Note that the actual executable (shown as "MyApp" in the screenshot, which I have doctored a bit to protect the innocent) is located inside a "bin" sub-directory along with all of the necessary shared-library files. In the main directory is a short shell script ("MyApp.sh") that looks like this:

#!/bin/bash
unset QT_PLUGIN_PATH   
appname=$(basename "$0" .sh)
dirname=$(dirname "$0")
cd "$dirname/bin"
export LD_LIBRARY_PATH=`pwd`
./$appname "$@"

... the user is expected to run the MyApp.sh script, which will set the LD_LIBRARY_PATH variable appropriately and then run the executable file.

It's not the most elegant thing in the world, but it gets the job done (much like Linux itself, heh).

Linux分发文件树的屏幕快照

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM