夜燕 發表於 2023-9-2 00:00:00

Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题

<p>
        <span><strong>问题描述</strong></span></p>
<p>
        安装Qt5.15.0后,在运行测试用例时弹出错误:</p>
<blockquote>
        <p>
                qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.<br>
                This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.</p>
        <p>
                Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.</p>
        <p>
                Aborted (core dumped)</p>
</blockquote>
<p>
        根据问题描述,虽然能够找到但是不能加载Qt平台插件“xcb”,虽然接下来又说重新安装可能能够解决,这个可能的话,还是尽量作为最下的选择吧。</p>
<p>
        <span><strong>定位问题</strong></span></p>
<p>
        修改配置文件~/.bashrc:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterbash" id="highlighter_491218">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="bash plain">$ vim ~/.bashrc</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
        <div class="codetool" id="codetool">
                <div class="code_n">
                        <textarea></textarea>
</div>
        </div>
</div>
<p>
        在最末尾添加如下语句,会在qtcreator启动时,列出详细的错误提示。</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterbash" id="highlighter_736798">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="bash functions">export</code> <code class="bash plain">QT_DEBUG_PLUGINS=1</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
        <div class="codetool" id="codetool">
                <div class="code_n">
                        <textarea></textarea>
</div>
        </div>
</div>
<p>
        如下:</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" alt="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" src="https://zhuji.jb51.net/uploads/img/202305/a27a1795e469bdd538d93a613678d2a1.jpg"></p>
<p>
        保存退出编辑,使配置文件生效:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterbash" id="highlighter_743717">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="bash plain">$ </code><code class="bash functions">source</code> <code class="bash plain">~/.bashrc</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
        <div class="codetool" id="codetool">
                <div class="code_n">
                        <textarea></textarea>
</div>
        </div>
</div>
<p>
        启动qtcreator会弹出如下详细错误信息:</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" alt="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" src="https://zhuji.jb51.net/uploads/img/202305/882896540a57e072a0ef5eb049000eb7.jpg"></p>
<p>
        在打印的错误信息的最下面,找到了引发错误的真正原因:</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" alt="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" src="https://zhuji.jb51.net/uploads/img/202305/87641f32d453b8e329209fba239084a0.jpg"></p>
<p>
        也就是Qt动态链接库的问题,当加载libqxcb.so库的时候,还需要加载libxcb-xinerama库。<br>
        切换到报错libxcb.so所在目录:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterbash" id="highlighter_94847">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                        <div class="line number2 index1 alt1">
                                                                2</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="bash comments">#替换为自己的报错目录</code>
</div>
                                                                <div class="line number2 index1 alt1">
                                                                        <code class="bash plain">$ </code><code class="bash functions">cd</code> <code class="bash plain">/home/brainiac/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
        <div class="codetool" id="codetool">
                <div class="code_n">
                        <textarea></textarea>
</div>
        </div>
</div>
<p>
        运行ldd libqxcb.so,查看关联内容:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterbash" id="highlighter_236183">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="bash plain">$ ldd libqxcb.so</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
        <div class="codetool" id="codetool">
                <div class="code_n">
                        <textarea></textarea>
</div>
        </div>
</div>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" alt="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" src="https://zhuji.jb51.net/uploads/img/202305/ece62cd86cda40fce803689f476abf7b.jpg"></p>
<p>
        发现不存在libxcb-xinerama.so.0库。</p>
<p>
        <span><strong>解决方法</strong></span></p>
<p>
        安装libxcb-xinerama库:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterbash" id="highlighter_290078">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                        <div class="line number2 index1 alt1">
                                                                2</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="bash comments">#如果还存在其他依赖库没有安装,也一并安装。</code>
</div>
                                                                <div class="line number2 index1 alt1">
                                                                        <code class="bash plain">$ </code><code class="bash functions">sudo</code> <code class="bash plain">apt-get </code><code class="bash functions">install</code> <code class="bash plain">libxcb-xinerama0</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
        <div class="codetool" id="codetool">
                <div class="code_n">
                        <textarea></textarea>
</div>
        </div>
</div>
<p>
        安装完成后,再次查看关联内容,发现已经修复问题:</p>
<div class="jb51code">
        <div>
                <div class="syntaxhighlighterbash" id="highlighter_935173">
                        <div class="toolbar">
                                <span>?</span>
</div>
                        <table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
                                                        <div class="line number1 index0 alt2">
                                                                1</div>
                                                </td>
                                                <td class="code">
                                                        <div class="container">
                                                                <div class="line number1 index0 alt2">
                                                                        <code class="bash plain">$ ldd libqxcb.so</code>
</div>
                                                        </div>
                                                </td>
                                        </tr></tbody></table>
</div>
        </div>
        <div class="codetool" id="codetool">
                <div class="code_n">
                        <textarea></textarea>
</div>
        </div>
</div>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" alt="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" src="https://zhuji.jb51.net/uploads/img/202305/fc4de69768bbc05c143b7b22d8a2a402.jpg"></p>
<p>
        再次运行qt程序,就可以正常运行了。</p>
<p>
        <img style="max-width:100%!important;height:auto!important;"title="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" alt="Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题" src="https://zhuji.jb51.net/uploads/img/202305/9e325edbfe487617b319206a49cd6f60.jpg"></p>
<p>
        后记</p>
<p>
        又可以愉快的coding了。</p>
<p>
        <span><strong>总结</strong></span></p>
<p>
        到此这篇关于Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题的文章就介绍到这了,更多相关Ubuntu18.04解决Qt出现qt.qpa.plugin内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!</p>
<p>
        原文链接:https://blog.csdn.net/LOVEmy134611/article/details/107212845</p>
頁: [1]
查看完整版本: Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题