問(wèn)題描述
安裝Qt5.15.0后,在運(yùn)行測(cè)試用例時(shí)彈出錯(cuò)誤:
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ù)問(wèn)題描述,雖然能夠找到但是不能加載Qt平臺(tái)插件“xcb”,雖然接下來(lái)又說(shuō)重新安裝可能能夠解決,這個(gè)可能的話,還是盡量作為最下的選擇吧。
定位問(wèn)題
修改配置文件~/.bashrc:
在最末尾添加如下語(yǔ)句,會(huì)在qtcreator啟動(dòng)時(shí),列出詳細(xì)的錯(cuò)誤提示。
export QT_DEBUG_PLUGINS=1
如下:
![](/d/20211016/fbe9a5dcf259898cc6fc61fb86fd5782.gif)
保存退出編輯,使配置文件生效:
啟動(dòng)qtcreator會(huì)彈出如下詳細(xì)錯(cuò)誤信息:
![](/d/20211016/66517c59414b1f5a09ae5f2501823911.gif)
在打印的錯(cuò)誤信息的最下面,找到了引發(fā)錯(cuò)誤的真正原因:
![](/d/20211016/11472998828679999146600753f1d90e.gif)
也就是Qt動(dòng)態(tài)鏈接庫(kù)的問(wèn)題,當(dāng)加載libqxcb.so庫(kù)的時(shí)候,還需要加載libxcb-xinerama庫(kù)。
切換到報(bào)錯(cuò)libxcb.so所在目錄:
#替換為自己的報(bào)錯(cuò)目錄
$ cd /home/brainiac/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/
運(yùn)行l(wèi)dd libqxcb.so,查看關(guān)聯(lián)內(nèi)容:
![](/d/20211016/1aa468aa32a52f445e4f278e50759d2d.gif)
發(fā)現(xiàn)不存在libxcb-xinerama.so.0庫(kù)。
解決方法
安裝libxcb-xinerama庫(kù):
#如果還存在其他依賴庫(kù)沒(méi)有安裝,也一并安裝。
$ sudo apt-get install libxcb-xinerama0
安裝完成后,再次查看關(guān)聯(lián)內(nèi)容,發(fā)現(xiàn)已經(jīng)修復(fù)問(wèn)題:
![](/d/20211016/92cacf9cbf8b070864f8a18a9da94570.gif)
再次運(yùn)行qt程序,就可以正常運(yùn)行了。
![](/d/20211016/52c4fedd11900dfa982be61691464209.gif)
后記
又可以愉快的coding了。
總結(jié)
到此這篇關(guān)于Ubuntu18.04下解決Qt出現(xiàn)qt.qpa.plugin:Could not load the Qt platform plugin “xcb“問(wèn)題的文章就介紹到這了,更多相關(guān)Ubuntu18.04解決Qt出現(xiàn)qt.qpa.plugin內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!