86

I'm using Ubuntu 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 a widget-type application, it fails with the 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 colleague, 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.

The below command had no impact:

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

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?

0

26 Answers 26

87

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

Sign up to request clarification or add additional context in comments.

3 Comments

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 stackoverflow.com/a/29560278/12401525
I needed a * also at the end of the *.so* because there were numbers at the end of the file name, after the extension. Also, there was no /gcc_64/ in the path. Like this: for l in /home/YOU/.venvs/YOURVENV/lib/python3.13/site-packages/PyQt6/Qt6/lib/*.so*; do
If you can't install libxcb-cursor0 for Ubuntu OS (Unable to locate package), should check if you enabled all option in Software and Updates > Ubuntu Software under the "Downloadable from the Internet" section. This setting can also be found by running software-properties-gtk.
37

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!

4 Comments

I tried to implement this on my Dockerfile and got a new error WebEngineContext is used before QtWebEngineQuick::initialize() or OpenGL context creation failed. [1:1:0922/214114.391383:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180. "/usr/local/lib/python3.11/site-packages/PySide6/Qt/plugins/platforms/libqoffscreen.so" unloaded library
@Adam, Thank you for letting me know. Actually, I didn't use this on the Dockerfile but now I know that it won't work in that way, thanks
what ended up working for me was a combination of your suggestion and one more line, so I had to have both ENV QT_QPA_PLATFORM=offscreen and ENV QTWEBENGINE_DISABLE_SANDBOX=1. Thanks for getting me halfway there!
QT_QPA_PLATFORM=offscreen works, but now my app does not appear on the screen at all.
26

I solved this problem by running this command in console

sudo apt install libxcb-xinerama0

The original link here

Comments

21

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

Comments

6

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

sudo yum install xcb-util*

Comments

5

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

pip uninstall PyQt5

1 Comment

This is a Qt question, not a PyQt one.
5

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 Comment

the only solution that worked (already tried one by one)
3

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.

Comments

3

My solution to this was to set the appropriate DISPLAY variable. Specifically, export DISPLAY=0.0 fixed the issue. The issue disappeared after that, curiously...

Comments

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.

1 Comment

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
2

I'm using opencv with PyQt5, and this did work for me:

pip uninstall opencv-python opencv-contrib-python opencv-python-headless
pip install opencv-python-headless

Comments

2

After a fresh installation of Qt Creator, I met the same issue.

I solved it by installing libxcb-xinerama0.

sudo apt install libxcb-xinerama0

Comments

1

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

sudo dnf install xcb-util*

Comments

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

Comments

1

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.

Comments

1

I was using OpenCV in a Python virtual environment in WSL. For me, this error was fixed after running this command.

sudo apt install xcb

1 Comment

This didn't make a difference in my case
1

first, echo $QT_QPA_PLATFORM, to see if it is xcb second, locate where the qt plugins is, such as /anaconda3/envs/envsam/lib/python3.10/site-packages/cv2/qt/plugins/platforms ls, then we rm libqxcb.so which will solve the problem.Hope this will work for you all!

Comments

1

None of the answers above worked for me. This is what I tried and it worked.

sudo apt install libxcb-xinerama0 libxcb-xkb1 libxcb1 libxcb-glx0 libqt5gui5 libqt5core5a libqt5widgets5 qt5-qmake qtbase5-dev

1 Comment

Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?
0

For me this error was due to a mismatch between python PyQt5 and Ubuntu QT6, which I solved via:

pip uninstall pyqt5
sudo apt install qt6-base-dev
pip install pyqt6

Comments

0

If you use SSH to remotely operate the Linux server and run the GUI program, this may be an environmental variable problem.Run your program with sudo -E instead of sudo,it will retain your environment variables and increase permissions at the same time. Maybe you need to execute twice.

 sudo -E /path/to/your/program

Suggest using MobaXterm, which provides GUI callback support.

Comments

0
export QT_QPA_PLATFORM=wayland

Adding the above export assignment works on Wayland in Ubuntu Mantic OS.

Comments

0

check whether libQt6XcbQpa.so.6 is existed in you appfolder/lib.

  • if not found, then check your deploy script, like qmake or cmake.
    qt_generate_deploy_script in cmake can automatically copy it.
  • if libQt6XcbQpa.so.6 existed in appfolder/lib, then check yout executable RUNPATH or RPATH using below command:
readelf -d <executable> | grep -E 'RUNPATH|RPATH'

it should contain like $ORIGIN;$ORIGIN/../lib.
if it does not contain, then you should check you cmake.

Comments

0

For conda users,

conda install xcb-util xcb-util-cursor xcb-util-image xcb-util-keysyms xcb-util-renderutil xcb-util-wm

worked for me.

Comments

0

For debian 12 with Xfce4 as default DE, apt install -y libqt5gui5 solves the problem.

Comments

0

No answer here hits the real reason, so here's the solution:

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

The issue is with the QT_QPA_PLATFORM_PLUGIN_PATH being empty.

Comments

-3
export QT_QPA_PLATFORM=offscreen 

This fixed, as it is written in the link provided by OP.

1 Comment

Why did you copy an already existing post?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.