The QT release program under linux cannot be opened by double-clicking the solution

phenomenon

Programs developed by Qt can be opened using ./terminal, but cannot be opened after double-clicking.

Stage one

Right-click the executable program and select properties. If the executable program type is "application/x-sharedlib", add the following content to the QT pro file, clear it and recompile the release version;

QMAKE_LFLAGS += -no-pie

The executable program at this time is "x-executable", double-click to see if it can be started.

Stage two

If you still can't open after stage 1, you can write a small demo at this time, create a new project with an interface, and do nothing. After compiling, see if it can be opened by double-clicking. If it can be opened, but a more complicated project cannot be opened. The explanation is an environmental problem; the
reason is analyzed.
Double-click on the graphical interface, the environment is the file manager, and use ./ is in the command line interface, which is a shell script. When the shell starts, some scripts will be executed to change environment variables; if a complex project relies on third-party libraries , Double-clicking the executable directly cannot be opened.
Solution
Modify the global environment variables and add the current path of the executable program to the following configuration file (depending on the library is generally at the same level as the executable program):

/etc/ld.so.conf

Execute the following command to make the setting effective immediately:

sudo ldconfig

Double-click the executable program again, it can be opened normally.

Stage three

The project is too large and there are other software on the computer to modify the environment variables. After these operations, you may still not be able to double-click to open. The following describes the double-clicking of the shell script to start, which looks the same to the user.
1. Edit a shell script, such as runHWT.sh, and place it in the executable file directory with the following content:

#!/bin/bash
#workdir当前工作路径
workdir=$(cd $(dirname $0); pwd)	
#echo $workdir
export LD_LIBRARY_PATH=$workdir	#添加临时环境变量
cd $workdir
./HardWareTest		#HardWareTest是可执行文件名

At this point, you can run the program in the terminal./runHWT.sh, but you can't open it even after double-clicking it.

2. Set the shell script to open by double-clicking.
Open the file manager-Edit-Preferences-Behavior, check "Run executable text files when opening them";
right-click runHWT.sh, select the permission tab, and check Allow as a program execution file , Double-click "runHWT.sh" to execute the program directly;

3. Create a desktop shortcut
In order to look more like a program, create a desktop shortcut with icons;
create the file /home/chw/Desktop/runHWT.sh.desktop on the desktop and edit vim runHWT.sh.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=runHWT
Comment=硬件测试程序
Exec=/home/chw/HSCompany/HardWareTest/HWTrelease-20210119/runHWT.sh
Icon=/home/chw/HSCompany/HardWareTest/HWTrelease-20210119/image/HWTlogo.png
Terminal=false
StartupNotify=true
Type=Application
Categories=Application;Development;

Where Exec is the full path of the shell script, Icon is the software icon path, png format, save and exit, you can see an icon named "runHWT" on the desktop, at this time double-click the shortcut icon to start the software.

Guess you like

Origin blog.csdn.net/weixin_40355471/article/details/112241927