无法打开 qcreator qt.qpa.plugin:在“”中找不到 Qt 平台插件“xcb”

无法打开 qcreator qt.qpa.plugin:在“”中找不到 Qt 平台插件“xcb”

我在 Ubuntu 上。当我qtcreator在终端上输入时,我得到:

QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/bin/plugins/platforms/libqxcb.so"
Found metadata in lib /usr/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": 331008
}


In /usr/bin/plugins/platforms/libqxcb.so:
  Plugin uses incompatible Qt library (5.13.0) [release]
"The plugin '/usr/bin/plugins/platforms/libqxcb.so' uses incompatible Qt library. (5.13.0) [release]" 
         not a plugin
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/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.

Aborted (core dumped)

我一直在寻找答案,但找不到能够正确解决我的问题的答案。

答案1

我在运行使用从源代码安装的 Qt 构建的应用程序时出现此错误消息(这是由于我安装 Qt 的方式造成的)。

快速

export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms

会将上述错误转变为qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms",所以这不是一个完整的解决方案。

就我而言,解决方案是安装xorgxorg-dev- 以及其他软件包。然后从源重新安装 Qt。

这些是我安装的所有软件包(在 ubuntu 20.04 上):

sudo apt install libfontconfig1-dev libfreetype6-dev libx11-dev libx11-xcb-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev   \
                 libxcb1-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev                \
                 libxcb-sync0-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev                    \
                 libxcb-xinerama0-dev libxkbcommon-dev libxkbcommon-x11-dev libclang-dev                                            \
                 freeglut3-dev mesa-utils libdrm-dev libgles2-mesa-dev                                                              \
                 binutils g++ cmake g++ mesa-common-dev build-essential libglew-dev libglm-dev                                      \
                 make g++ pkg-config libgl1-mesa-dev libxcb1-dev libfontconfig1-dev libxkbcommon-x11-dev python libgtk-3-dev        \
                 build-essential default-jre openjdk-8-jdk-headless android-sdk android-sdk-platform-23 libc6-i386                  \
                 libdrm-dev libgles2-mesa-dev libzc-dev libxcb-sync-dev libsmartcols-dev libicecc-dev libpthread-workqueue-dev      \
                 libgstreamer1.0-dev libgcrypt20-dev libqt5gui5-gles qca-qt5-2-utils xorg xorg-dev

请注意,default-jre openjdk-8-jdk-headless android-sdk android-sdk-platform-23可能libc6-i386只有当您需要构建 android 项目时才需要它。

以下是我从源代码安装 Qt 的方法:

export QT_VERSION=5.15.1
export QT5BINDIR=/usr/local/Qt-$QT_VERSION/bin
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/qt5/lib
export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms
export QT_QPA_FONTDIR=/usr/lib/x86_64-linux-gnu/qt5/lib/fonts

cd ~/Downloads/qt/qt-everywhere-src-$QT_VERSION/
sed -i 's/python /python3 /' qtdeclarative/qtdeclarative.pro \
           qtdeclarative/src/3rdparty/masm/masm.pri


./configure     -opensource -confirm-license    \
                -sysconfdir /etc/xdg            \
                -dbus-linked                    \
                -system-harfbuzz                \
                -nomake examples                \
                -no-rpath                       \
                -skip qtwebengine

make -j4
sudo make -j4 install
echo "Adding environment variables"
PATH=/usr/local/Qt-$QT_VERSION/bin:$PATH
export PATH

ldd /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/*.so

主要文献来源是Beyond Linux® From Scratch(System V 版本)-Qt-5.15.1

相关内容