Qt运行程序报以下错误:
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, vkkhrdisplay, linuxfb, minimalegl, offscreen, wayland-egl, minimal, xcb, vnc, wayland.
按照网上查到的办法,在 ~/.bashrc 文件末尾加上
export QT_DEBUG_PLUGINS=1
用source命令使其生效
source ~/.bashrc
在终端中重新运行程序,打印了详细的报错信息:
qt.core.plugin.factoryloader: checking directory path "/home/bosscome/Develop/bosscome/fib_modify/repo/dev/bin/platforms" ... qt.core.library: "/home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/libqxcb.so" cannot load: Cannot load library /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/libqxcb.so: (libxcb-cursor.so.0: 无法打开共享对象文件: 没有那个文件或目录) qt.core.plugin.loader: QLibraryPrivate::loadPlugin failed on "/home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/libqxcb.so" : "Cannot load library /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/libqxcb.so: (libxcb-cursor.so.0: 无法打开共享对象文件: 没有那个文件或目录)" 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, vkkhrdisplay, linuxfb, minimalegl, offscreen, wayland-egl, minimal, xcb, vnc, wayland.
发现报错的真正原因来源于Qt动态库加载的问题,跟随网上的步骤,跳转到对应的动态库目录,用ldd命令执行该动态库,进一步分析报错原因:
ldd /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/libqxcb.so
分析输出内容,发现有两个动态库 not found(其实是同一个):
linux-vdso.so.1 (0x00007fff1cda5000)
libQt6XcbQpa.so.6 => /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/../../lib/libQt6XcbQpa.so.6 (0x00007fca4b960000)
libxkbcommon-x11.so.0 => /lib/x86_64-linux-gnu/libxkbcommon-x11.so.0 (0x00007fca4b93f000)
libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007fca4b8fd000)
libxcb-cursor.so.0 => not found
libxcb-icccm.so.4 => /lib/x86_64-linux-gnu/libxcb-icccm.so.4 (0x00007fca4b8f6000)
libxcb-image.so.0 => /lib/x86_64-linux-gnu/libxcb-image.so.0 (0x00007fca4b6f1000)
libxcb-keysyms.so.1 => /lib/x86_64-linux-gnu/libxcb-keysyms.so.1 (0x00007fca4b6ea000)
libxcb-randr.so.0 => /lib/x86_64-linux-gnu/libxcb-randr.so.0 (0x00007fca4b6d7000)
libxcb-render-util.so.0 => /lib/x86_64-linux-gnu/libxcb-render-util.so.0 (0x00007fca4b6d0000)
libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007fca4b6cb000)
libxcb-sync.so.1 => /lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007fca4b6c1000)
libxcb-xfixes.so.0 => /lib/x86_64-linux-gnu/libxcb-xfixes.so.0 (0x00007fca4b6b7000)
libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007fca4b6a6000)
libxcb-shape.so.0 => /lib/x86_64-linux-gnu/libxcb-shape.so.0 (0x00007fca4b6a1000)
libxcb-xkb.so.1 => /lib/x86_64-linux-gnu/libxcb-xkb.so.1 (0x00007fca4b683000)
libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fca4b659000)
libQt6OpenGL.so.6 => /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/../../lib/libQt6OpenGL.so.6 (0x00007fca4b5b7000)
libQt6Gui.so.6 => /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/../../lib/libQt6Gui.so.6 (0x00007fca4abf3000)
libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007fca4ab69000)
libQt6Core.so.6 => /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/../../lib/libQt6Core.so.6 (0x00007fca4a4df000)
libX11-xcb.so.1 => /lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007fca4a4da000)
libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007fca4a39d000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fca4a397000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fca4a374000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fca4a190000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fca4a041000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fca4a026000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fca49e34000)
libxcb-cursor.so.0 => not found
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fca49d0b000)
libgthread-2.0.so.0 => /lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fca49d04000)
libxcb-util.so.1 => /lib/x86_64-linux-gnu/libxcb-util.so.1 (0x00007fca49afe000)
libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007fca49af8000)
libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fca49af0000)
libEGL.so.1 => /lib/x86_64-linux-gnu/libEGL.so.1 (0x00007fca49adb000)
libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007fca49a92000)
libQt6DBus.so.6 => /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/../../lib/libQt6DBus.so.6 (0x00007fca499cc000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fca499b0000)
libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fca498f1000)
libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007fca49839000)
libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007fca49805000)
libicui18n.so.56 => /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/../../lib/libicui18n.so.56 (0x00007fca4936a000)
libicuuc.so.56 => /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/../../lib/libicuuc.so.56 (0x00007fca48fb2000)
libicudata.so.56 => /home/bosscome/Qt/Qt6/6.5.1/gcc_64/plugins/platforms/../../lib/libicudata.so.56 (0x00007fca475cf000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fca475c5000)
/lib64/ld-linux-x86-64.so.2 (0x00007fca4ba1b000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fca47552000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007fca47536000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fca47508000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007fca474ff000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007fca474ae000)
libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007fca47476000)
libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007fca473c5000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fca4739c000)
liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007fca4737b000)
libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007fca4725d000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007fca4723a000)
那就安装它(注意缺失的动态库名 .so 后面的那个数字):
sudo apt install libxcb-cursor0
安装完后再次运行动态库,发现已经没有 not found 了
重新运行我们自己的程序,一切正常了。。。。。。
2024-07-30补充:
若缺失的动态库名称是以数字结尾(如 libxkbcommon-x11.so.0 => not found),在安装过程中添加.so 后面的那个数字时,要先加一个减号,即:
sudo apt install libxkbcommon-x11-0
PS:我是在安装时输入动态库名称后按Tab键发现的。