解决Ubuntu下QT could not find or load the Qt platfom plugin "xcb"

在安装QT5.10.1之后,打开texstudio以及okular这两个文本编辑器时都报了如下错误


This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Available platform plugins are: wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx.

Reinstalling the application may fix this problem.

查找错误

设置环境变量, 用 sudo gedit ~/.bashrc 打开配置环境的文件, 打开之后如下图

解决Ubuntu下QT could not find or load the Qt platfom plugin "xcb"
在文件末尾添加如下代码, 和图上位置一样即可

export QT_DEBUG_PLUGINS=1

再次运行texstudio, 这次显示了错误信息

解决Ubuntu下QT could not find or load the Qt platfom plugin "xcb"
这个错误是说在/usr/bin/platforms下未找到相应的库。

如何解决

网上的解决办法大多是以下几个:

  1. 添加环境变量,将QT安装目录下的plugins文件加入到环境变量中
  2. QT版本高了,需要重新安装

将环境变量添加进去之后仍然报上述错误,在网上找了很久没找到解决办法,于是,我突然想到把platforms文件夹移动到 /usr/bin目录下。
解决Ubuntu下QT could not find or load the Qt platfom plugin "xcb"
这下报的错误变了:
解决Ubuntu下QT could not find or load the Qt platfom plugin "xcb"
这里是说QT5.10.1的库不兼容。这时想到网上有说QT版本太高的缘故,就去安装了一个QT5.5的版本,将安装之后的platforms文件夹移动到/usr/bin目录下,成功解决。