Redirect qDebug output to file with PyQt5

Viewed 5824

I implemented an application using python2.7, Qt5.5 and PyQt5. I got the Python-logger working using logging-Module: Log-Messages are both sent to stderr and to a log-file.

However, the Qt log messages only appear in stderr and I could not find a way to redirect them to a file.

In order to narrow down the problem, I tried this:

>>> from PyQt5.QtCore import qDebug
>>> import sys
>>> sys.stderr = open("stderr.txt", 'w')
>>> qDebug('test message')
test message
>>> sys.stderr.close()
>>> # stderr.txt is empty

Note: The pure-Qt-way seems to be manipulating a QDebug object, but I was not able to find the class within PyQt5.

Question: How can I have qDebug write to a file stderr.txt?

1 Answers
Related