[PyQt] Better alternative to create QApplication without using a context manager

BPL spscener84 at gmail.com
Sat Jul 20 12:46:20 BST 2019


Phil,

A while ago I'd reported a bug related to the clipboard getting screwed up,
more
info about it here
https://www.riverbankcomputing.com/pipermail/qscintilla/2019-June/001404.html

At that time you'd provided a bug fix where you'd need to create a
QApplication
using a context manager, that bug fix worked wonderfully.

That said, wouldn't be possible to provide a better solution that doesn't
involve using a context manager at all? IMHO that'd be a much better
clean&ideal solution, that way all existing pyqt application would benefit
from the bug fix without having to change any existing production code,
plus... in pyside2 the bug doesn't exist when using the normal way of
creating the QApplication instance, check this one out:

USE_PYQT = True

if USE_PYQT:
    from PyQt5.Qt import *
else:
    from PySide2.QtGui import *
    from PySide2.QtCore import *
    from PySide2.QtWidgets import *

if __name__ == '__main__':
    app = QApplication([])
    w = QPlainTextEdit()
    w.setPlainText("hello world")
    w.show()
    app.exec_()

When using pyside2 the clipboard bug doesn't exist while in pyqt right
now you're forced to use the context manager, otherwise you'll get the
bug... but ideally both should expose the same right behaviour
without forcing the user to use any context manager :)

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190720/be2110ee/attachment.html>


More information about the PyQt mailing list