CentOS 运行Qt程序报错及中文显示为小方框问题

基于pyqt5开发了GUI程序,想要在x86架构下的CentOS7系统下使用pyinstaller打包成可执行程序并运行,打包比较顺利,但运行时报错了,这里记录下问题解决过程。

报错信息如下:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

Aborted (core dumped)

解决步骤

  1. 设置环境变量QT_DEBUG_PLUGINS
export QT_DEBUG_PLUGINS=1
  1. 再次运行程序查看最下方的报错信息,会显示缺少的库
...
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/opt/tdtool/platforms" ...
Cannot load library /tmp/_MEIhUBkwl/PyQt5/Qt5/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/tmp/_MEIhUBkwl/PyQt5/Qt5/plugins/platforms/libqxcb.so" : "Cannot load library /tmp/_MEIhUBkwl/PyQt5/Qt5/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)"
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
...
  1. 去这个网站http://rpm.pbone.net/搜索库对应的包名
  2. 使用yum安装缺少的包,我的环境缺少如下包
yum install libxcb libxcb-devel libXrender libXrender-devel xcb-util-wm xcb-util-wm-devel xcb-util-image xcb-util-image-devel xcb-util-keysyms xcb-util-keysyms-devel xcb-util-renderutil xcb-util-renderutil-devel libxkbcommon-x11 libxkbcommon-x11-devel
  1. 再次运行程序,成功

通过MobaXterm运行GUI程序

MobaXterm通过SSH连接服务器后,需要启动X Server并设置环境变量DISPLAY后才可以

  1. 启动X Server
    在这里插入图片描述

  2. 设置DISPLAY环境变量

export DISPLAY=172.xx.xx.xx:0.0		# 变量值是下图中绿色框中的内容

在这里插入图片描述
如果DISPLAY如下图所示自动设置了,则不需要设置,此时使用echo $DISPLAY是能够看到结果的
在这里插入图片描述

界面中文显示为小方框问题

界面上的中文显示为小方框是系统缺少字体导致,解决办法:

  1. 在 /usr/share/fonts路径下新建windows目录
  2. 将 C:\Windows 目录下的Fonts整个文件夹拷贝到linux系统的 /usr/share/fonts/windows 路径下,即 /usr/share/fonts/windows/Fonts路径下是字体文件
  3. 重新运行GUI程序,界面上中文显示正常
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值