36

I know that there is a great amount of answers regarding this topic, however none of them helped me. I'm using Ubunty 20.04 via Oracle VM Virtual Box and I faced exactly the same error as all other people. After building Qt6 source code using official Qt manual I'm trying to run different projects to test if everything works properly. Console-type projects build and run properly. There are no errors. Unfortunately, when I try to run Widget-type application it fails with well-known error.

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.

My collegue, who has Qt6 working properly on his Ubuntu, saw that I don't have libqxcb.so in the .../qtbase/plugins/platforms and shared it with me. Unfortunately, it didn't help much. Only the error message has changed a bit: it says that plugin was found, but couldn't be used. I tried different solutions from Internet, but none of them helped. One of the most popular

sudo apt install libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0

had no impact.

Also, there's more verbose output with environmental variable 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.

It shows that libQt6XcbQpa.so.6 file is missing. After running ldd /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so to show the dependencies, I got the following output:

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)

So this file is really missing. What can be the potential problem and how do I fix it? Thank you in advance!

CuriousPan
  • 783
  • 1
  • 8
  • 14
  • First check if your Qt6 build tree contains said plugin or not. If not, you need to figure out why. If it did, you probably skipped a step to copy the libraries from the build directory to their final location (like, say, `~/qt6`). – Botje Jun 18 '21 at 14:07
  • @Botje , how can I check build tree? – CuriousPan Jun 18 '21 at 14:09
  • Do you have package `libxkbcommon-dev` installed? – Ross Rogers Jun 18 '21 at 15:04
  • Oh wow, I would have been stuck forever if I didn't find this question showing off the `QT_DEBUG_PLUGINS=1` trick to diagnose which library I was missing. Your question answered my question; thanks! – matthew-mcallister May 04 '23 at 03:28

14 Answers14

25

Thank you everyone who tried to help to resolve my problem. The answer came from official Qt forum. Link to solution: https://forum.qt.io/topic/127696/qt-qpa-plugin-could-not-load-the-qt-platform-plugin-xcb-in-even-though-it-was-found/22

Basically, the problem was in lack of some dependencies. Because of specificity of Qt6 I had to install dependencies from Qt5 building manual. It's hard to say lack of which dependency caused the problem, but after installing all of them and reconfiguring and rebuilding source code, project builds properly.

CuriousPan
  • 783
  • 1
  • 8
  • 14
  • 43
    for pyqt6 in ubuntu 20.04, following spell in forum linked above, solved the problem for me `sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev` – harish Oct 21 '21 at 14:48
  • The dependency installs didn't work for me. Thanks for sharing though. – Sridhar Sarnobat Mar 02 '22 at 02:37
  • Dependencies install help to resolve my about Calibre app. Thank you – aliftc12 Apr 02 '22 at 14:21
  • 4
    @harish , this should be part of answer. solved my issue too. – undefined May 10 '22 at 10:42
  • 3
    No need to install all these dependencies or "-dev" packages to run a PyQt6 program. The smallest set of packages which is needed to make it work seems to be the following: `libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxkbcommon-x11-0`. I wonder if there is a package which install them as dependencies in a cleaner way. – Francesco Frassinelli Feb 23 '23 at 16:11
  • 6
    For PySide6 on debian-11.7, all I needed was `sudo apt-get install libxcb-cursor0` – JimB May 08 '23 at 14:16
18

For the Qt 6.5.0 release, the missing library was libxcb-cursor.so.0, resolved with

sudo apt install libxcb-cursor0

With that, the sample widget and gui projects from QtCreator run correctly built with Qt 6.5.0. libxcb-cursor.so.0 wasn't previously needed for Qt 6.4.0.

I identified the missing library with this shell code

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

This scans all the install Qt libraries, extracts their required dependency libraries related to xcb, then prints which debian package provides each libxcb* library. On my system it reported a debian package for each libxcb*.so library except libxcb-cursor.so.0

Rizzer
  • 404
  • 4
  • 11
  • My original solution used `for l in $(cat)` to loop over and inspect the xcb libs. It's probably better to use `while read lib` since `$(cat)` might not work cleanly, see https://stackoverflow.com/a/29560278/12401525 – Rizzer Apr 05 '23 at 16:14
16

I solved this problem by running this command in console

sudo apt install libxcb-xinerama0 

The original link here

Tuananhcwrs
  • 971
  • 7
  • 5
10

One of the easiest approaches which helped me,type this in console:

export QT_QPA_PLATFORM=offscreen

More you can read here. I hope it would help you!

Vasyl Lyashkevych
  • 1,920
  • 2
  • 23
  • 38
5

If you're on Centos, this solved the problem for me:

sudo yum install xcb-util*
Ivan Sivak
  • 7,178
  • 3
  • 36
  • 42
2

I got this same message for a completely different reason. I had had to recreate a python virtual env from scratch after it wouldn't install tensorflow-gpu due to package inconsistencies. That environment had for many months been working correctly with qt, and I had all the qt lib*.so dependencies correctly installed. My rebuilt environment did now have tensorflow-gpu and no package inconsistencies according to conda, but my program was broken now at runtime with this Qt platform plugin xcb error. It turned out that while rebuilding the env i had installed opencv-python via pip, which installed some various Qt packages specific to opencv and python. But, if I installed qt via conda, before installing opencv-python via pip, then pip did not subsequently install those Qt packages for opencv-python, and the xcb plugin error was now fixed.

J B
  • 348
  • 1
  • 6
  • `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 Sep 27 '22 at 20:01
2

For me pip install pyqt6 worked.

My application was running on matplotlib and needed an external GUI. So, I tried to install TK, it didn't worked. On installing pyqt5, it gave me the same error as yours, so I remove it. PyQT6 though worked perfectly. I had also installed libxcb (sudo yum install libxcb), but xcb plugin should not be needed in wayland env.

1

opencv-python now uses Qt6 (at least at version 4.7.0.72). Installing Qt6 solved it for me

sudo apt install qt6-base-dev
Megacier
  • 394
  • 4
  • 9
1

I'm working with Linux Mint 21 and using VSCode as my editor. I was just trying to run a simple GUI application when I encountered an issue. I have installed Pyenv and was able to resolve the problem by running the following command: sudo apt install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev This command installs several development libraries and dependencies that are required by some Python packages. By running this command, I was able to fix the issue I was facing.

1

I solved this problem by installing PyQt5 dependences

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

After fresh install QT Creator, I met the same issue. I solved it by install libxcb-xinerama0

sudo apt install libxcb-xinerama0

0

On Rocky Linux 8.6, this solution also works. Thanks @Ivan Sivak

sudo dnf install xcb-util*
p3ch3xcr
  • 1
  • 1
0

you can try delete pyqt5. I have successed using this method.

pip uninstall PyQt5

0

As for me, the platforms directory is absent from the directory qrelease. Just copy it from the Qt installing directory and the error will be gone.

W.Perrin
  • 4,217
  • 32
  • 31