Re: QApplication.clipboard() segfault on GNU/Linux

BPL <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <CAAfY3fbgH0NOttMWLFSJ4Qwii5_BWa08qmDxnWyZmSmBWopYeQ@mail.gmail.com>
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 <[email protected]> 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 <[email protected]> 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    [email protected]
>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
> --
> Hugo Slepicka
> *[email protected] <[email protected]>*
> *+1 631 855 5717*
> _______________________________________________
> PyQt mailing list    [email protected]
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.