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
相关推荐
鹏大师运维3 分钟前
【功能介绍】信创终端系统上各WPS版本的授权差异
linux·wps·授权·麒麟·国产操作系统·1024程序员节·统信uos
筱源源5 分钟前
Elasticsearch-linux环境部署
linux·elasticsearch
knighthood200117 分钟前
解决:ros进行gazebo仿真,rviz没有显示传感器数据
c++·ubuntu·ros
pk_xz1234562 小时前
Shell 脚本中变量和字符串的入门介绍
linux·运维·服务器
小珑也要变强2 小时前
Linux之sed命令详解
linux·运维·服务器
Lary_Rock4 小时前
RK3576 LINUX RKNN SDK 测试
linux·运维·服务器
云飞云共享云桌面6 小时前
8位机械工程师如何共享一台图形工作站算力?
linux·服务器·网络
Peter_chq7 小时前
【操作系统】基于环形队列的生产消费模型
linux·c语言·开发语言·c++·后端
一坨阿亮7 小时前
Linux 使用中的问题
linux·运维
dsywws8 小时前
Linux学习笔记之vim入门
linux·笔记·学习