我正在使用QT在信创PC机上开发应用程序,因为PC机的特殊使用需要,我作为运维人员需要通过开机设置启动专用应用程序,即使用root用户启动界面的应用程序,实际的使用者将在thtf用户下使用PC机上的应用。目前功能已经实现了,但是却无法输入中文,我采用的解决方式是:
1、在执行程序的目录中复制了开发所用QT版本的plugins目录;
2、在启动脚本中设置了lib目录和plugins目录位置;
3、在启动脚本中设置了输入法类型:fctix;
具体的启动脚本如下:
```bash
#!/bin/bash
# Allow reader to access the X server
xhost +SI:localuser:reader
# Switch to reader user and run the command as reader
sudo -u reader bash << 'EOF'
# Set DISPLAY and XAUTHORITY for reader user
export DISPLAY=:0
export XAUTHORITY=/home/thtf/.Xauthority
# Set locale for Chinese input
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
# Set XDG_RUNTIME_DIR for reader user (UID 1001)
export XDG_RUNTIME_DIR=/run/user/$(id -u)
# Ensure necessary runtime directory exists and has correct permissions (this part runs as reader)
mkdir -p $XDG_RUNTIME_DIR
chmod 0700 $XDG_RUNTIME_DIR
# Ensure necessary libraries and plugins are loaded
export LD_LIBRARY_PATH=/home/reader/RM:$LD_LIBRARY_PATH
export QT_QPA_PLATFORM_PLUGIN_PATH=/home/reader/RM/plugins
export QT_QPA_PLATFORM=xcb
# Set input method environment variables for fcitx
export XMODIFIERS=@im=fcitx
export QT_IM_MODULE=fcitx
export GTK_IM_MODULE=fcitx
# Ensure fcitx is running (uncomment if necessary)
# fcitx &
# Start D-Bus if not running
eval $(dbus-launch)
export DBUS_SESSION_BUS_ADDRESS
# Launch the program with debugging enabled (uncomment if debugging is needed)
# QT_DEBUG_PLUGINS=1 /home/reader/ReadingRoom/MouseKeyEvent > /home/reader/debug_log.txt 2>&1
# Launch the MouseKeyEvent program
/home/reader/RM/MouseKeyEvent
EOF