如何解决如何检查Qt5是否支持该系统?
我想在不同的系统上运行PyQt5应用程序。当它在Qt5支持的系统上运行时,一切都很好。否则,我想自动切换到基于文本的界面。
当我尝试在错误的环境(例如,通过SSH进行测试)中启动应用程序时,出现以下错误:
qt.qpa.xcb: could not connect to display
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,webgl,xcb.
Aborted (core dumped)
很不幸,该应用程序崩溃了,我无法使用try ... except
块。有什么方法可以检查兼容性并避免崩溃?
以下是PyQt5应用的最小示例:
from PyQt5.QtWidgets import QApplication
QApplication([]) # this line leads to crash as described above
它的唯一用途是它在窗帘情况下崩溃。
为了将来我。
目前,解决方案是
if __name__ == '__main__':
import subprocess
child = subprocess.Popen([sys.executable,'-c','from PyQt5.QtWidgets import QApplication; QApplication([])'],stderr=subprocess.PIPE)
child.wait()
ret_code = child.returncode
if ret_code == 0:
gui.run() # load the GUI
else:
print('This platform is not supported by Qt5')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。