在 Linux 上从源代码构建的 Qt5 上找不到 Qt 平台插件 xcb

Posted

技术标签:

【中文标题】在 Linux 上从源代码构建的 Qt5 上找不到 Qt 平台插件 xcb【英文标题】:Could not find the Qt platform plugin xcb, on Qt5 build from source on Linux 【发布时间】:2020-05-04 02:49:33 【问题描述】:

我在 Debian 10 32 位上构建 Qt5。然后我创建了一个最小的 Qt 项目,运行 $ ~/qt/qt-everywhere-src-5.12.7/qtbase/bin/qmake project.promake,但是当我尝试执行应用程序时,我执行以下操作:

发生了什么事?

$ ./release/project 
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: linuxfb, minimal, offscreen, vnc, webgl.

Aborted

更多信息:

$ QT_DEBUG_PLUGINS=1 release/project 
QFactoryLoader::QFactoryLoader() checking directory path "/home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqlinuxfb.so, metadata=

    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": 
        "Keys": [
            "linuxfb"
        ]
    ,
    "archreq": 0,
    "className": "QLinuxFbIntegrationPlugin",
    "debug": false,
    "version": 330752



Got keys from plugin meta data ("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqminimal.so"
Found metadata in lib /home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqminimal.so, metadata=

    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": 
        "Keys": [
            "minimal"
        ]
    ,
    "archreq": 0,
    "className": "QMinimalIntegrationPlugin",
    "debug": false,
    "version": 330752



Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "/home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqoffscreen.so"
Found metadata in lib /home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqoffscreen.so, metadata=

    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": 
        "Keys": [
            "offscreen"
        ]
    ,
    "archreq": 0,
    "className": "QOffscreenIntegrationPlugin",
    "debug": false,
    "version": 330752



Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqvnc.so"
Found metadata in lib /home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqvnc.so, metadata=

    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": 
        "Keys": [
            "vnc"
        ]
    ,
    "archreq": 0,
    "className": "QVncIntegrationPlugin",
    "debug": false,
    "version": 330752



Got keys from plugin meta data ("vnc")
QFactoryLoader::QFactoryLoader() looking at "/home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqwebgl.so"
Found metadata in lib /home/user/qt/qt-everywhere-src-5.12.7/qtbase/plugins/platforms/libqwebgl.so, metadata=

    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": 
        "Keys": [
            "webgl"
        ]
    ,
    "archreq": 0,
    "className": "QWebGLIntegrationPlugin",
    "debug": false,
    "version": 330752



Got keys from plugin meta data ("webgl")
QFactoryLoader::QFactoryLoader() checking directory path "/home/user/QtProjects/project/release/platforms" ...
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: linuxfb, minimal, offscreen, vnc, webgl.

Aborted

【问题讨论】:

显示QT_DEBUG_PLUGINS=1 ./release/project 的输出 刚刚将该信息附加到问题中。看起来它正在寻找可执行路径中的platforms 目录。不知道这意味着什么。 你的Qt编译创建的插件必须在/home/user/QtProjects/project/release/platforms文件夹下,根据你显示的日志,它只适用于webgl。如果您想使用 X11,那么您必须在编译 Qt 源代码时使用-qt-xcb 选项。见doc.qt.io/qt-5/linux-requirements.html 嗯,很有趣,再编译一次吧。关于为什么 Qt 在编译时默认不选择它的任何评论? 因为这是开发人员的任务:-)。 【参考方案1】:

libqxcb.so 应该在您的应用程序的platforms 子目录中找到。如果您想更改其搜索位置,请查看qt.conf ini 文件,该文件控制插件搜索路径以及其他路径

【讨论】:

以上是关于在 Linux 上从源代码构建的 Qt5 上找不到 Qt 平台插件 xcb的主要内容,如果未能解决你的问题,请参考以下文章

PyQt5 5.8.2 在 Windows 10 上从源代码构建

/usr/bin/ld: 在 Linux Mint 上的 Qt Creator 中构建 Qt5 应用程序时找不到 lGL

在 android 设备上找不到使用 QStandardPath 创建的文件

在 Linux 机器上从源代码构建 Qt-4.3.2

在 Mac 上找不到 Qt 库

在 linux 上从源代码编译 LLVM