QT应用启动失败排查方法

背景

启动QT应用经常会碰到应用启动失败,qt platform plugin无法启动,比如:

复制代码
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: xcb.

Aborted (core dumped)

排查办法

打开QT Plugin加载调试开关

复制代码
export QT_DEBUG_PLUGINS=1

重新启动应用,会得到更详细的错误信息,如下

复制代码
QFactoryLoader::QFactoryLoader() checking directory path "/home/netease/working/hermes/pc_mac/build/bin/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/libqxcb.so"
Found metadata in lib /home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "archreq": 0,
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/netease/working/hermes/pc_mac/build/bin/platforms" ...
Cannot load library /home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/libqxcb.so: (libxcb-xinput.so.0: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/libqxcb.so" : "Cannot load library /home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/libqxcb.so: (libxcb-xinput.so.0: 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.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

Aborted (core dumped)

可以看出根本原因是Cannot load library /home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/libqxcb.so: (libxcb-xinput.so.0: cannot open shared object file: No such file or directory)

加载不了libqxcb.so, 依赖的动态库libxcb-xinput.so.0找不到, ldd查看如下:

复制代码
[netease@netease-Precision-3630-Tower ~/working/hermes/pc_mac/build/bin]$ ldd /home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/libqxcb.so
        linux-vdso.so.1 (0x00007ffc3330b000)
        libQt5XcbQpa.so.5 => /home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/../../lib/libQt5XcbQpa.so.5 (0x00007fc35406c000)
        libQt5Gui.so.5 => /home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/../../lib/libQt5Gui.so.5 (0x00007fc353800000)
        libQt5Core.so.5 => /home/netease/working/hermes/pc_mac/build/bin/plugins/platforms/../../lib/libQt5Core.so.5 (0x00007fc352b8f000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc352806000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc352415000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc3521f6000)
        libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007fc351ff4000)
        libxcb-icccm.so.4 => /usr/lib/x86_64-linux-gnu/libxcb-icccm.so.4 (0x00007fc351def000)
        libxcb-image.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-image.so.0 (0x00007fc351bea000)
        libxcb-shm.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007fc3519e7000)
        libxcb-keysyms.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-keysyms.so.1 (0x00007fc3517e4000)
        libxcb-randr.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-randr.so.0 (0x00007fc3515d4000)
        libxcb-render-util.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-render-util.so.0 (0x00007fc3513d0000)
        libxcb-render.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007fc3511c3000)
        libxcb-shape.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shape.so.0 (0x00007fc350fbf000)
        libxcb-sync.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007fc350db8000)
        libxcb-xfixes.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-xfixes.so.0 (0x00007fc350bb0000)
        libxcb-xinerama.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-xinerama.so.0 (0x00007fc3509ad000)
        libxcb-xinput.so.0 => not found
        libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fc350675000)
        libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007fc35046d000)
        libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007fc350252000)
        libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fc35002a000)
        libxcb-xkb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-xkb.so.1 (0x00007fc34fe0e000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc34fa70000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc34f858000)
        libGL.so.1 => /usr/lib/x86_64-linux-gnu/libGL.so.1 (0x00007fc34f5cc000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc34f3c8000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc35477b000)
        libxcb-util.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-util.so.1 (0x00007fc34f1c2000)
        libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007fc34efbb000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007fc34eda6000)
        libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fc34eba2000)
        libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fc34e99c000)
        libGLX.so.0 => /usr/lib/x86_64-linux-gnu/libGLX.so.0 (0x00007fc34e76b000)
        libGLdispatch.so.0 => /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007fc34e4b5000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc34e2ad000)

确实是 libxcb-xinput.so.0 => not found

解决办法

安装确实的三方库即可解决

复制代码
sudo apt install libxcb-xinput-dev
相关推荐
Linux运维老纪9 分钟前
运维之 Centos7 防火墙(CentOS 7 Firewall for Operations and Maintenance)
linux·安全·centos·云计算·运维开发·火绒
斯普信专业组16 分钟前
Ceph异地数据同步之-RBD异地同步复制(下)
linux·服务器·ceph
counsellor20 分钟前
CentOS 7安装hyperscan
linux·centos·hyperscan
电星托马斯23 分钟前
Linux系统CentOS 6.3安装图文详解
linux·运维·服务器·程序人生·centos
啞謎专家26 分钟前
CentOS中挂载新盘LVM指南:轻松扩展存储空间,解决磁盘容量不足问题
linux·运维·服务器
s_little_monster38 分钟前
【Linux】进程信号的捕捉处理
linux·运维·服务器·经验分享·笔记·学习·学习方法
一大Cpp1 小时前
Ubuntu与本地用户交流是两种小方法
linux·运维·ubuntu
小王不会写code1 小时前
CentOS 7 镜像源失效解决方案(2025年)
linux·运维·centos
zyplanke1 小时前
CentOS Linux升级内核kernel方法
linux·运维·centos
go_bai2 小时前
Linux环境基础开发工具——(2)vim
linux·开发语言·经验分享·笔记·vim·学习方法