<div dir="ltr"><div><div><div>Hi,<br><br></div>With a X11 build of Qt, if there's no X server available, or the DISPLAY env var is invalid, (ssh batch mode, ...)<br></div>then Qt exits (like in exit(1); ), with the message<br>
: cannot connect to X server <br><br></div>That's a non-feature of Qt to not raise exceptions, in order to be lighweight or more compatible,<br>but in the python side we'd expect a traceback, and that could be considered as a bug.<br>
<div><div><div><div><br>You can reproduce it simply:<br>DISPLAY="" python -c "from PyQt4 import QtGui; app = QtGui.QApplication([]); print 'Not executed' "<br></div><div></div><div><br></div><div>
A workaround is to trying to check if on an X11 build, and trying to assess the validity of DISPLAY env var with:<br>if hasattr(QtGui, 'QX11Info'):<br>    display = os.environ.get('DISPLAY')<br>    if display is None or not re.search(':\d', display): <br>
        raise RuntimeError('Invalid DISPLAY variable')        <br></div><div>But I think it'd be great if it could be raised within pyqt.<br></div><div><br clear="all"></div><div><div><br>-- <br>J</div></div></div>
</div></div></div>