how to capture log data in QTextEdit

Florian Bruhin me at
Mon Feb 22 16:13:47 GMT 2021

Hey Stefan,

On Sun, Feb 21, 2021 at 11:41:58AM -0500, Stefan Seefeld wrote:
> I'm trying to capture ("redirect") log data generated by a wrapped C++
> library to a QTextEdit. The internet is full of related questions, but I
> couldn't quite find a working example that matches my needs. I can configure
> my logger to either write to the console (stdout) or to a file, so what I'm
> looking for is a mechanism to attach a "listener" to the given file
> descriptor and let it emit a `readyRead` signal whenever data are available.
> For a reason I don't entirely understand, the `QFile` class does *not* emit
> that signal, and thus is unfortunately unsuitable for this.

I'm not sure why either, but FWIW that behavior is documented as well:

> So, does PyQt5 offer any classes that are equipped to listen to data being
> written to a file descriptor such that I could read them asynchronously ?
> The only examples I could find involve (tcp or udp) sockets or serial ports,
> but not simple files...

Despite the name, QSocketNotifier might work:
("Although the class is called QSocketNotifier, it is normally used for
other types of devices than sockets")

Here's an example using it on a Unix FIFO:

I'm not sure if I've ever tried it on an ordinary file, though.

Alternatively, maybe a QFileSystemWatcher would work:

Here's an example:


            me at | |
       GPG: 916E B0C8 FD55 A072 |
             I love long mails! |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <>

More information about the PyQt mailing list