如何解决 [RedHat7.5运行qtcreator时出现xcb插件问题]
1.问题现象
在 RedHat 7.5 系统中启动 Qt Creator 时,终端输出以下错误:
plaintext
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, xcb.:
2.问题原因
核心原因是 Qt 库版本冲突 或 依赖库加载异常:
- Qt Creator 自带的
xcb
插件(libqxcb.so
)依赖特定版本的 Qt 库和系统库(如libxcb
系列) - 系统中存在其他版本的 Qt 库(如
/usr/lib64/
下的系统默认库),导致插件加载时调用了不兼容的库文件 - 环境变量未正确配置,插件无法找到自带的依赖库
3.解决方法:通过启动脚本隔离环境
1. 创建启动脚本
在 Qt Creator 安装目录的 bin
文件夹下(以 /opt/qtcreator-5.0.3/bin/
为例)创建 qtcreator.sh
:
bash
# 进入安装目录的 bin 文件夹
cd /opt/qtcreator-5.0.3/bin/
# 创建脚本文件
cat > qtcreator.sh << 'EOF'
#!/bin/bash
# 强制使用 Qt Creator 自带的 Qt 库,避免系统库冲突
export LD_LIBRARY_PATH=/opt/qtcreator-5.0.3/lib/Qt/lib:$LD_LIBRARY_PATH
# 指定插件路径,确保 xcb 插件正确加载
export QT_PLUGIN_PATH=/opt/qtcreator-5.0.3/lib/Qt/plugins
# 启动 Qt Creator 主程序
/opt/qtcreator-5.0.3/bin/qtcreator "$@"
EOF
2. 赋予脚本执行权限
bash
chmod +x /opt/qtcreator-5.0.3/bin/qtcreator.sh
3. 通过脚本启动 Qt Creator
bash
# 直接运行脚本
/opt/qtcreator-5.0.3/bin/qtcreator.sh
4. (可选)简化启动命令
为了直接输入 qtcreator
即可启动,创建软链接到系统命令目录:
bash
sudo ln -s /opt/qtcreator-5.0.3/bin/qtcreator.sh /usr/bin/qtcreator
4.原理说明
LD_LIBRARY_PATH
:强制程序优先加载 Qt Creator 自带的 Qt 库(避免使用系统中不兼容的旧版本库)QT_PLUGIN_PATH
:明确指定插件路径,确保xcb
插件能找到所有依赖组件- 脚本隔离了系统环境变量的干扰,确保 Qt Creator 运行在独立、兼容的环境中
5.补充:若仍报错
若启动后提示缺失 libxcb-xxx.so
等库,安装系统依赖:
bash
sudo yum install -y libxcb libxcb-devel xcb-util libxkbcommon libxkbcommon-x11
之后在终端输入 qtcreator
即可启动。
版权声明 :本文采用 CC BY-NC-SA 4.0 协议,转载请注明出处。