QT6:"qt.qpa.plugin:无法在“”中加载Qt平台插件“xcb”,尽管找到了该插件。"

44

我知道有很多关于这个主题的答案,但是没有一个对我有帮助。我使用Oracle VM Virtual Box上的Ubuntu 20.04,并且遇到了和其他人完全相同的错误。 按照官方Qt手册构建Qt6源代码后,我尝试运行不同的项目以测试一切是否正常。控制台类型的项目构建和运行正常,没有错误。不幸的是,当我尝试运行窗口小部件类型的应用程序时,它会出现众所周知的错误。

t.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.
我的同事在他的Ubuntu上成功安装了Qt6,他发现我在.../qtbase/plugins/platforms中没有libqxcb.so文件,于是与我分享了这个文件。不幸的是,它并没有帮助太多。只是错误消息有点变化:它说找到了插件,但无法使用。我尝试了网络上的不同解决方案,但没有一个有效。其中最流行的一个是...
sudo apt install libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0

没有影响。

此外,使用环境变量QT_DEBUG_PLUGINS=1可以获得更详细的输出:

QFactoryLoader::QFactoryLoader() checking directory path "/home/curiouspan/qt6-build/qtbase/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqeglfs.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqeglfs.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "eglfs"
        ]
    },
    "archreq": 1,
    "className": "QEglFSIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqlinuxfb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "linuxfb"
        ]
    },
    "archreq": 1,
    "className": "QLinuxFbIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqminimal.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqminimal.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "archreq": 1,
    "className": "QMinimalIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("minimal")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqminimalegl.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqminimalegl.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimalegl"
        ]
    },
    "archreq": 1,
    "className": "QMinimalEglIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqoffscreen.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqoffscreen.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "archreq": 1,
    "className": "QOffscreenIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqvnc.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqvnc.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "vnc"
        ]
    },
    "archreq": 1,
    "className": "QVncIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("vnc")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "archreq": 0,
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 393728
}


Got keys from plugin meta data QList("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/curiouspan/QtTestProjects/build-WidgetTestApp-Own_Desktop-Debug/platforms" ...
Cannot load library /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so: (libQt6XcbQpa.so.6: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so" : "Cannot load library /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so: (libQt6XcbQpa.so.6: 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: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

这表明缺少libQt6XcbQpa.so.6文件。 运行ldd /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so以显示依赖项,我得到了以下输出:

linux-vdso.so.1 (0x00007fffc8770000)
    libQt6XcbQpa.so.6 => not found
    libQt6Gui.so.6 => /home/curiouspan/qt6-build/qtbase/plugins/platforms/../../lib/libQt6Gui.so.6 (0x00007f0873306000)
    libQt6Core.so.6 => /home/curiouspan/qt6-build/qtbase/plugins/platforms/../../lib/libQt6Core.so.6 (0x00007f087295d000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f087277c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f087258a000)
    libEGL.so.1 => /lib/x86_64-linux-gnu/libEGL.so.1 (0x00007f0872573000)
    libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f0872436000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0872430000)
    libQt6DBus.so.6 => /home/curiouspan/qt6-build/qtbase/plugins/platforms/../../lib/libQt6DBus.so.6 (0x00007f0872262000)
    libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f087222e000)
    libOpenGL.so.0 => /lib/x86_64-linux-gnu/libOpenGL.so.0 (0x00007f0872202000)

所以这个文件确实丢失了。 可能的问题是什么,我该如何解决?谢谢!


首先检查你的Qt6构建树中是否包含该插件。如果没有,你需要找出原因。如果有,你可能跳过了将库从构建目录复制到它们的最终位置(比如说,~/qt6)的步骤。 - Botje
@Botje,我该如何检查构建树? - CuriousPan
你是否已经安装了 libxkbcommon-dev 软件包? - Ross Rogers
哇,如果我没有发现这个问题展示了“QT_DEBUG_PLUGINS=1”技巧来诊断我缺少哪个库,我可能会一直卡在那里。你的问题回答了我的问题,谢谢! - matthew-mcallister
17个回答

34
在Qt 6.5.0版本中,缺失的库是libxcb-cursor.so.0,可以通过以下方式解决:
sudo apt install libxcb-cursor0

因此,使用Qt 6.5.0构建的QtCreator示例小部件和GUI项目可以正确运行。在Qt 6.4.0中以前不需要libxcb-cursor.so.0。

我使用以下shell代码识别了缺失的库

for l in /path/to/Qt/6.5.0/gcc_64/lib/*.so; do
  echo $l; objdump -p $l | grep NEEDED | sed "s/^/\t"/;
 done | grep xcb | awk '{print $2}' \
| while read lib; do echo $lib; dlocate $lib; done

这将扫描所有已安装的 Qt 库,提取与 xcb 相关的其所需的依赖库,然后打印出每个 libxcb* 库由哪个 Debian 软件包提供。在我的系统上,它为每个 libxcb*.so 库报告了一个 Debian 软件包,除了 libxcb-cursor.so.0。


1
我的原始解决方案使用 for l in $(cat) 循环遍历并检查 xcb 库。最好使用 while read lib,因为 $(cat) 可能无法正常工作,请参见 https://dev59.com/Bl0b5IYBdhLWcg3wJ-Qy#29560278。 - Rizzer
1
我可以确认这是解决问题的正确方法。 - undefined
1
我找了好几个星期终于找到了这个问题。谢谢 @Rizzer - undefined

31

51
在Ubuntu 20.04中使用PyQt6,根据上述论坛中的建议,使用以下命令可以解决我的问题:sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev - harish
1
依赖项安装对我来说没有起作用。不过还是谢谢你的分享。 - Sridhar Sarnobat
依赖项安装可以帮助解决我关于Calibre应用程序的问题。谢谢。 - aliftc12
6
@harish,这应该是答案的一部分。也解决了我的问题。 - undefined
4
不需要安装所有这些依赖项或“-dev”包来运行PyQt6程序。 看起来使其工作所需的最小软件包集似乎是以下内容:libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxkbcommon-x11-0。我想知道是否有一种以更清晰的方式将它们安装为依赖项的软件包。 - Francesco Frassinelli
8
在debian-11.7上使用PySide6,我所需要的只是sudo apt-get install libxcb-cursor0 - JimB

17
我通过在控制台中运行以下命令解决了这个问题。
sudo apt install libxcb-xinerama0 

原始链接在这里


16

我用过的最简单的方法是,在控制台中输入以下命令:

export QT_QPA_PLATFORM=offscreen

更多内容可在此处阅读。希望能对您有所帮助!


我尝试在我的Dockerfile上实施这个,但是出现了一个新的错误WebEngineContext在QtWebEngineQuick::initialize()之前被使用或OpenGL上下文创建失败。 [1:1:0922/214114.391383:ERROR:zygote_host_impl_linux.cc(100)]在没有--no-sandbox的情况下以root身份运行是不支持的。请参阅https://crbug.com/638180。 "/usr/local/lib/python3.11/site-packages/PySide6/Qt/plugins/platforms/libqoffscreen.so"卸载库 - undefined
@Adam,谢谢你告诉我。实际上,我没有在Dockerfile中使用这个,但现在我知道它不会以那种方式工作,谢谢。 - undefined
1
最终对我起作用的是你的建议和另外一行代码的结合,所以我必须同时使用ENV QT_QPA_PLATFORM=offscreenENV QTWEBENGINE_DISABLE_SANDBOX=1。感谢你帮我解决了一半的问题! - undefined
1
QT_QPA_PLATFORM=offscreen可以工作,但是现在我的应用程序根本不会显示在屏幕上。 - undefined

5
如果您使用的是Centos操作系统,以下方法可以帮助解决问题:

sudo yum install xcb-util*

3

对我来说,pip install pyqt6 可以解决问题。

我的应用程序运行在 matplotlib 上,并需要一个外部 GUI。所以,我尝试安装 TK,但它没有起作用。在安装 pyqt5 时,它给了我与你的相同的错误,所以我将其删除了。然而,PyQT6 却完美地工作。我还安装了 libxcb (sudo yum install libxcb),但在 wayland 环境下不应该需要 xcb 插件。


3

我通过安装PyQt5依赖解决了这个问题

sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev

2
我因为完全不同的原因收到了相同的信息。由于软件包不一致,我必须从头开始重新创建一个Python虚拟环境,因为它无法安装tensorflow-gpu。那个环境已经在很多月里与qt一起正常工作,我已经正确安装了所有的qt lib*.so 依赖项。我的重建环境现在已经有了tensorflow-gpu,而且conda也没有软件包不一致问题,但是我的程序在运行时现在出现了这个Qt平台插件xcb错误。事实证明,在重建环境时,我通过pip安装了opencv-python,它安装了一些特定于opencv和python的Qt软件包。但是,如果我先通过conda安装qt,然后再通过pip安装opencv-python,那么pip就不会随后安装那些opencv-python的Qt软件包,xcb插件错误现在已经修复了。

opencv-python was indeed the culprit for me. As soon as I installed it, I started facing the error from OP. Unfortunately, first installing pyqt through conda, and only after that installing opencv-python through pip, did not solve the issue for me. What solved the issue is:
  1. first install pyqt through conda
  2. now do conda install -c conda-forge opencv
  3. finally: pip install opencv-python
- ihopethiswillfi

1

opencv-python现在使用Qt6(至少在版本4.7.0.72中)。安装Qt6对我来说解决了这个问题。

sudo apt install qt6-base-dev

这是我唯一有效的方法! - liwei2633

1
对我来说,目录qrelease中缺少platforms目录。只需从Qt安装目录中复制它,错误就会消失。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接