15 Answers
15

Use ldd (man ldd) to show shared library dependencies. Running this on libqxcb.so

.../platforms$ ldd libqxcb.so

shows that xcb depends on libQt5DBus.so.5 in addition to libQt5Core.so.5 and libQt5Gui.so.5 (and many other system libs). Add libQt5DBus.so.5 to your collection of shared libs and you should be ready to move on.

In my case sudo apt-get install libx11-xcb1 fixed the problem. But your recommendation of using ldd was what pointed me to the correct library to install. Thanks!
– MondKinMar 17 '15 at 0:37

3

In my case I also had to add libQt5XcbQpa.so.5 to the lib folder.
– elsamukoNov 21 '15 at 20:10

2

If you still have this problem after going through ldd, try finding the plugins/platforms directory within your Qt installation. Try to copy this entire directory to the same place as your binary or shared library file. If that works, you may set LD_LIBRARY_PATH (hacky) or, as mentioned in the answer by @bossbarber, QT_QPA_PLATFORM_PLUGIN_PATH.
– cslOct 6 '16 at 7:06

As was posted earlier, you need to make sure you install the platform plugins when you deploy your application. Depending on how you want to deploy things, there are two methods to tell your application where the platform plugins (e.g. platforms/plugins/libqxcb.so) are at runtime which may work for you.

The first is to export the path to the directory through the QT_QPA_PLATFORM_PLUGIN_PATH variable.

QT_QPA_PLATFORM_PLUGIN_PATH=path/to/plugins ./my_qt_app

or

export QT_QPA_PLATFORM_PLUGIN_PATH=path/to/plugins
./my_qt_app

The other option, which I prefer is to create a qt.conf file in the same directory as your executable. The contents of which would be:

Wow! Thanks so much! Didn't know about qt.conf, it should on the first page of deployment FAQ
– user2440074Dec 18 '14 at 10:00

in my case for some reason the path inside the qt.conf (Plugins=plugins) was not recognized. I ended up supplying an empty qt.conf file, which let the global (hard coded) paths be overwritten with the qt.conf-defaults, in my case the plugins-Subfolder in the app-directory.
– B PiltzSep 6 '16 at 17:45

1

We were wondering why LD_LIBRARY_PATH wasn't working, but QT_QPA_PLATFORM_PLUGIN_PATH did the trick. Super-thanks.
– Ahmed FasihFeb 15 '18 at 19:03

2nd or 3rd time I come to this answer and it helps every time.
– kybNov 11 '18 at 20:26

I tried to start my binary, compiled with Qt 5.7, on Ubuntu 16.04 LTS where Qt 5.5 is preinstalled. Expectedly, it didn't work as is.

At first, I inspected the binary itself with ldd as was suggested here, and satisfied all "not found" dependencies. Then this notorious This application failed to start because it could not find or load the Qt platform plugin "xcb" error was thrown in.

What should be done on Linux to resolve this

At first, you should create platforms directory where your binary is, because it is the place where Qt looks for XCB library. Copy libqxcb.so there. I wonder why authors of other answers didn't mention this.

Then you may want to run your binary with QT_DEBUG_PLUGINS=1 environment variable set to check what dependencies of libqxcb.so unsatisfied. (You may also use ldd for this as suggested in the accepted answer).

Note the failing libQt5DBus.so.5 library. Copy it to your libraries path, in my case it was the same directory where my binary is (hence LD_LIBRARY_PATH=.). Repeat this process until all dependencies are satisfied.

I found that while there were unspecified dependencies on libQt5xcbQpa.so.5 and libQtDBus.so.5 I still needed to add the platforms folder as you indicates. THAT combination made it work.
– BSDNov 17 '17 at 16:30

Ubuntu 16.04 64bit.
I got the problem for apparently no reasons. The night before I watched a movie on my VideoLan instance, that night I would like to watch another one with VideoLan. VLC just didn't want to run because of the error into the question.
I google a bit and I found the solution it solved my problem: from now on, VLC is runnable just like before. The solution is this comand:

So, I just need to install all packages from the list of dependencies? And this will work? Also I found the file libqxcb.so in the QT SDK dir, but placing it in the usr/lib directory does not resolved my problem.
– locomotionJun 14 '13 at 11:51

I installed all packages mentioned on that page, but it didn't help. I found the information, that the platform plugins must be in the directory of the executable in the folder "platforms". I put there xcb plugin, now the erroe changed: "Failed to load platform plugin "xcb". Available platforms are: xcb "
– locomotionJun 14 '13 at 20:32

This worked for me on Ubuntu 17.10 (but having this problem since 16.04!) export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/. Unfortunately it only fixed my VLC, not Virtualbox that has the same error...
– TailsNov 23 '17 at 20:54

In my case, I needed to deploy two Qt apps on an Ubuntu virtualbox guest. One was command-line ("app"), the other GUI_based ("app_GUI").

I used "ldd app" to find out what the required libs are, and copied them
to the Ubuntu guest.
While the command-line executable "app" worked ok, the GUI-based executable crashed, giving
the "Failed to load platform plugin "xcb" error. I checked ldd for libxcb.so, but this too had no missing dependencies.

The problem seemed to be that while I did copy all the right libraries I accidentally had copied also libraries that were already present at the guest system.. meaning that (a) they were unnecessary to copy them in the first place and (b) worse, copying them produced incompatibilities between the install libraries.
Worse still, they were undetectable by ldd like I said..

The solution? Make sure that you copy libraries shown as missing by ldd and absolutely no extra libraries.

I faced the same problem when after installing Viber. It had all required qt libraries in /opt/viber/plugins/.
I checked dependencies of /opt/viber/plugins/platforms/libqxcb.so and found missing dependencies. They were libxcb-render.so.0, libxcb-image.so.0, libxcb-icccm.so.4, libxcb-xkb.so.1
So I resolved my issue by installing missing packages with this libraries:

So, I spent about a day trying to figure out what was the issue; tried all the proposed solutions, but none of that worked like installing xcb libs or exporting Qt plugins folder. The solution that suggested to use QT_DEBUG_PLUGINS=1 to debug the issue didn't provide me a direct insight like in the answer - instead I was getting something about unresolved symbols within Qt5Core.

That gave me a hint, though: what if it's trying to use different files from different Qt installations? On my machine I had standard version installed in /home/username/Qt/ and some local builds within my project that I compiled by myself (I have other custom built kits as well in other locations). Whenever I tried to use any of the kits (installed by Qt maintenance tool or built by myself), I would get an "xcb error".

The solution was simple: provide the Qt path through CMAKE_PREFIX_PATH and not though Qt5_DIR as I did, and it solved the problem. Example:

I link all Qt stuff statically to the generic Linux builds of my open source projects. It makes life a bit easier. You just need to build static versions of Qt libraries first. Of course this cannot be applied to closed source software due to licensing issues. The deployment of Qt5 apps on Linux is currently a bit problematic, because Ubuntu 12.04, for example, doesn't have Qt5 libraries in the package repositories.

I had this problem, and on a hunch I removed the Qt Configs from my environment. I.e.,

rm -rf ~/.config/Qt*

Then I started qtcreator and it reconfigured itself with the existing state of the machine. It no longer remembered where my projects were, but that just meant I had to browse to them "for the first time" again.

But more importantly it built itself a coherent set of library paths, so I could rebuild and run my project executables again without the xcb or qxcb libraries going missing.

Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).