首頁 > 軟體

Ubuntu18.04下解決Qt出現qt.qpa.plugin:Could not load the Qt platform plugin 「xcb「問題

2020-08-12 00:14:15

問題描述

安裝Qt5.15.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, xcb.

Aborted (core dumped)

根據問題描述,雖然能夠找到但是不能載入Qt平臺外掛「xcb」,雖然接下來又說重新安裝可能能夠解決,這個可能的話,還是儘量作爲最下的選擇吧。

定位問題

修改組態檔~/.bashrc:

$ vim ~/.bashrc

在最末尾新增如下語句,會在qtcreator啓動時,列出詳細的錯誤提示。

export QT_DEBUG_PLUGINS=1

如下:

儲存退出編輯,使組態檔生效:

$ source ~/.bashrc

啓動qtcreator會彈出如下詳細錯誤資訊:

在列印的錯誤資訊的最下面 下麪,找到了引發錯誤的真正原因:

也就是Qt動態鏈接庫的問題,當載入libqxcb.so庫的時候,還需要載入libxcb-xinerama庫。
切換到報錯libxcb.so所在目錄:

#替換爲自己的報錯目錄
$ cd /home/brainiac/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/

執行ldd libqxcb.so,檢視關聯內容:

$ ldd libqxcb.so

發現不存在libxcb-xinerama.so.0庫。

解決方法

安裝libxcb-xinerama庫:

#如果還存在其他依賴庫沒有安裝,也一併安裝。
$ sudo apt-get install libxcb-xinerama0

安裝完成後,再次檢視關聯內容,發現已經修復問題:

$ ldd libqxcb.so

再次執行qt程式,就可以正常執行了。

後記

又可以愉快的coding了。

總結

到此這篇關於Ubuntu18.04下解決Qt出現qt.qpa.plugin:Could not load the Qt platform plugin 「xcb「問題的文章就介紹到這了,更多相關Ubuntu18.04解決Qt出現qt.qpa.plugin內容請搜尋it145.com以前的文章或繼續瀏覽下面 下麪的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com