[PyQt] QApplication.clipboard() segfault on GNU/Linux
BPL
spscener84 at gmail.com
Tue Jul 23 17:50:58 BST 2019
To really understand this I'd suggest you also reading these 2 related
posts:
https://www.riverbankcomputing.com/pipermail/qscintilla/2019-June/001404.html
and
https://www.riverbankcomputing.com/pipermail/pyqt/2019-July/041958.html
That said, with the current latest pyqt you can guarantee the data copied
into the clipboard will be preserved
by using a QApplication context manager, like this:
from PyQt5.QtWidgets import QApplication
if __name__ == '__main__':
FORCE_BUG = True
if not FORCE_BUG:
with QApplication([]) as app:
clipboard = app.clipboard()
clipboard.setText("azerty")
print(QApplication.instance().clipboard().text())
print(app.clipboard().text())
print(clipboard.text())
else:
app = QApplication([])
clipboard = app.clipboard()
clipboard.setText("azerty")
print(QApplication.instance().clipboard().text())
print(app.clipboard().text())
print(clipboard.text())
Ideally it wouldn't be necessary to use any context manager at all... but
not sure how difficult would be for Phil
to provide that behaviour :/
On Tue, Jul 23, 2019 at 6:29 PM Hugo Slepicka <hhslepicka at gmail.com> wrote:
> This is what worked for me for all OSs:
>
>
> clipboard = QApplication.clipboard()
>
> clipboard.setText(copy_text)
>
> event = QEvent(QEvent.Clipboard)
>
> QApplication.instance().sendEvent(clipboard, event)
>
>
>
> On Tue, Jul 23, 2019 at 9:08 AM Tiger-222 <contact at tiger-222.fr> wrote:
>
>> FTR I have the same error on macOS.
>>
>>
>>
>> -----
>> Mickaƫl Schoentgen.
>> [FR] Personal blog: http://www.tiger-222.fr
>> --
>> Sent from: http://python.6.x6.nabble.com/PyQt-f1792048.html
>> _______________________________________________
>> PyQt mailing list PyQt at riverbankcomputing.com
>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
> --
> Hugo Slepicka
> *hhslepicka at gmail.com <hhslepicka at gmail.com>*
> *+1 631 855 5717*
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190723/5d252797/attachment-0001.html>
More information about the PyQt
mailing list