I've been having this error message when running an app built with Qt installed from sources (so this was due to the way I have installed Qt).
A quick
export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms
will transform the error above into qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms"
, so this is not a complete solution.
In my case the solution was to install xorg
and xorg-dev
- and other packages for that matter. Then reinstall Qt from sources.
These are all the packages that I have installed (on 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
Mind you that default-jre openjdk-8-jdk-headless android-sdk android-sdk-platform-23
and possibly libc6-i386
too, are only required if you need to build android projects.
And this is how I installed Qt from sources:
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
A major source of documentation is Beyond Linux® From Scratch (System V Edition) - Qt-5.15.1
.