Hello, I created a QTextEdit where I wanted to display log messages. A logging.Handler should do this job.
It worked with one thread well, but when I start a QThread the text on all widgets is removed and I get many errors in my konsole: X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 Extension: 152 (RENDER) Minor opcode: 25 (RenderCompositeGlyphs32) Resource id: 0x0 X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 Extension: 152 (RENDER) Minor opcode: 25 (RenderCompositeGlyphs32) Resource id: 0x0 X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177 Extension: 152 (RENDER) Minor opcode: 25 (RenderCompositeGlyphs32) Resource id: 0x0 .. and so on I attatched a small example to this mail. Could anybody tell me what I'm doing wrong? Thanks for you help, Lukas
from PyQt4.QtCore import * from PyQt4.QtGui import * import logging class QtStreamHandler(logging.Handler): def __init__(self, parent, main): logging.Handler.__init__(self) self.parent = parent self.main = main self.textWidget = parent self.formater = logging.Formatter("%(message)s") def createLock(self): self.mutex = QMutex() def acquire(self): self.mutex.lock() def release(self): self.mutex.unlock() def emit(self,record): self.textWidget.appendPlainText(self.formater.format(record)) self.textWidget.moveCursor(QTextCursor.StartOfLine) self.textWidget.ensureCursorVisible() class Log(QDialog): def __init__(self, parent, main): super(Log, self).__init__(parent) self.parent = parent self.main = main self.layout = QVBoxLayout(self) self.logEdit = QPlainTextEdit(self) self.logEdit.setLineWrapMode(QPlainTextEdit.NoWrap) self.logEdit.setReadOnly(True) self.button = QPushButton(self) self.button.setText("Message") self.layout.addWidget(self.logEdit) self.layout.addWidget(self.button) self.connect(self.button, SIGNAL("clicked()"), self.message) self.show() def message(self): self.main.log.error("Log window") class MainWindow(QDialog): def __init__(self, parent, main): super(MainWindow, self).__init__() self.parent = parent self.main = main self.layout = QVBoxLayout(self) self.check = QCheckBox(self) self.check.setText("Foobar") self.combo = QComboBox(self) self.combo.addItem("aaaa") self.combo.addItem("bbbb") self.button = QPushButton(self) self.button.setText("Start Thread") self.button2 = QPushButton(self) self.button2.setText("Message") self.layout.addWidget(self.check) self.layout.addWidget(self.combo) self.layout.addWidget(self.button) self.layout.addWidget(self.button2) self.connect(self.button, SIGNAL("clicked()"), self.startThread) self.connect(self.button2, SIGNAL("clicked()"), self.message) self.show() def startThread(self): self.thread = Thread(self, self.main) self.connect(self.thread, SIGNAL("finished()"), lambda : self.main.log.error("Thread finished")) self.thread.start() def message(self): self.main.log.error("Main window") class Thread(QThread): def __init__(self, parent, main): super(Thread, self).__init__(parent) self.log = main.log def run(self): self.log.info("Thread...") class Main(QObject): def __init__(self): super(Main, self).__init__() logger = logging.getLogger("series60-remote") logger.setLevel(logging.DEBUG) self.logWindow = Log(None, self) dialogHandler = QtStreamHandler(self.logWindow.logEdit, self) logger.addHandler(dialogHandler) self.logWindow.show() self.log = logger self.window = MainWindow(None, self) app = QApplication([]) main = Main() app.exec_()
-- http://mail.python.org/mailman/listinfo/python-list