Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c++ - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Screenshot of Linux distribution file tree


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...