如何检查Qt5是否支持该系统?

时间:2020-08-26 06:59:50

标签: python pyqt pyqt5

我想在不同的系统上运行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')

0 个答案:

没有答案