問題描述
安裝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)
根據(jù)問題描述,雖然能夠找到但是不能加載Qt平臺插件“xcb”,雖然接下來又說重新安裝可能能夠解決,這個可能的話,還是盡量作為最下的選擇吧。
定位問題
修改配置文件~/.bashrc:
在最末尾添加如下語句,會在qtcreator啟動時,列出詳細的錯誤提示。
export QT_DEBUG_PLUGINS=1
如下:

保存退出編輯,使配置文件生效:
啟動qtcreator會彈出如下詳細錯誤信息:

在打印的錯誤信息的最下面,找到了引發(fā)錯誤的真正原因:

也就是Qt動態(tài)鏈接庫的問題,當加載libqxcb.so庫的時候,還需要加載libxcb-xinerama庫。
切換到報錯libxcb.so所在目錄:
#替換為自己的報錯目錄
$ cd /home/brainiac/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/
運行l(wèi)dd libqxcb.so,查看關聯(lián)內(nèi)容:

發(fā)現(xiàn)不存在libxcb-xinerama.so.0庫。
解決方法
安裝libxcb-xinerama庫:
#如果還存在其他依賴庫沒有安裝,也一并安裝。
$ sudo apt-get install libxcb-xinerama0
安裝完成后,再次查看關聯(lián)內(nèi)容,發(fā)現(xiàn)已經(jīng)修復問題:

再次運行qt程序,就可以正常運行了。

后記
又可以愉快的coding了。
總結
到此這篇關于Ubuntu18.04下解決Qt出現(xiàn)qt.qpa.plugin:Could not load the Qt platform plugin “xcb“問題的文章就介紹到這了,更多相關Ubuntu18.04解決Qt出現(xiàn)qt.qpa.plugin內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!