LoginSignup
19
10

More than 3 years have passed since last update.

`qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.` というエラーが起きたときの対処

Posted at

Ubuntu Desktop(18.04)環境でrstudioを起動したらこんな感じのエラーが起きた

$ rstudio 
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, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.

QPAのプラグインでxcbを使おうとしたが初期化に失敗したとのこと。

QPAはQt Platform Abstractionの略で、プラットフォーム(windows,ios,xcb)を抽象化して扱うQtの仕組みの一つ。プラグイン機構を採用しており、プラットフォームを選べる/追加できる仕組みとなっている。

今回はX11上で動かそうとしたので、xcb(Qt上はqxcbというプラグイン名)を使おうとしたが、初期化がうまくいかなかった、ということみたい。その初期化がうまくいかなかった原因が分かれば苦労しないんですけどね。。

エラー文「"Could not load the Qt platform plugin"」でざっくり調べると、以下がヒット。

回答で2つ書かれている。

  • プラグインが使う共有ライブラリがちゃんとそろっているかlddで調べろ
  • 環境変数QT_DEBUG_PLUGINS=1 を与えて実行しろ

なるほど。

lddで見る

プラグインがどこにあるかは雑にfind /usr | grep "qxcb" で調べた。

今回はrstudio同梱のlibqxcb.soが引っかかったのでこれで見る。

$ ldd /usr/lib/rstudio/plugins/platforms/libqxcb.so 

linux-vdso.so.1 (0x00007ffdebd5a000)
(中略)
libxkbcommon-x11.so.0 => not found
libxkbcommon.so.0 => /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f651288c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6512688000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f65122ff000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f65120e7000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6511cf6000)
libxkbcommon-x11.so.0 => not found
(中略)

1つでもnot foundとなっている部分がある。この部分の共有ライブラリを用意する必要がある。

今回はaptで入れただけで済んだ。

sudo apt install libxkbcommon-x11-0

再度、lddを試すと、not foundの表示は消えた。この状態でrstudioを起動してみるとエラーにならず起動できた。

環境変数QT_DEBUG_PLUGINS=1を付ける

せっかくなので、こっちも試す。

apt remove libxkbcommon-x11-0をした後、同じエラーが出るようになった状態にしてから試した。

$ QT_DEBUG_PLUGINS=1 rstudio

(中略)

QFactoryLoader::QFactoryLoader() looking at "/usr/lib/rstudio/plugins/platforms/libqxcb.so"
Found metadata in lib /usr/lib/rstudio/plugins/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "archreq": 0,
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/rstudio/bin/platforms" ...
Cannot load library /usr/lib/rstudio/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: 共有オブジェクトファイルを開けません: そのようなファイルやディレクトリはありません)
QLibraryPrivate::loadPlugin failed on "/usr/lib/rstudio/plugins/platforms/libqxcb.so" : "Cannot load library /usr/lib/rstudio/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: 共有オブジェクトファイルを開けません: そのようなファイルやディレクトリはありません)"
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, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.

最後の4行は同じだが、それより前のログがわかりやすく出ていることが分かる。最後の4行を出すぐらいなら最初からこれぐらい出してほしさもある。

19
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
10