Qt 提供 qInstallMessageHandler(Qt5)
或者qInstallMsgHandler(Qt4)
,能夠對QDebug、QWarning、QError等進行重定向等處理。html
能夠參考Qt Assistant 的幫助文檔,或者參考Qt之日誌輸出文件進行實現。安全
簡單的日誌框架,能夠添加多個日誌的destination,能夠使用Signal/Slot機制方便的將日誌輸出到Widget。多線程
項目地址:QsLog的Bitbucket地址app
QxtLib的一部分,若是也是用QxtLib的其餘功能,確定也會用這個。可是我沒用過框架
項目地址:QxtLogger Class Referencespa
If you want to limit the total number of paragraphs in a QPlainTextEdit, as it is for example useful in a log viewer, then you can use the maximumBlockCount property. The combination of
setMaximumBlockCount()
andappendPlainText()
turnsQPlainTextEdit
into an efficient viewer for log text. The scrolling can be reduced with thecenterOnScroll()
property, making the log viewer even faster. Text can be formatted in a limited way, either using a syntax highlighter (see below), or by appending html-formatted text withappendHtml()
. WhileQPlainTextEdit
does not support complex rich text rendering with tables and floats, it does support limited paragraph-based formatting that you may need in a log viewer..net
上一段引用來自Qt的幫助文檔。組合 QPlainTextEdit 的 setMaximumBlockCount()
和 appendPlainText()
方法,來實現logger的顯示,能夠控制總共顯示的行數。線程
能夠設置總行數來控制顯示的日誌數量。日誌
若是基於qDebug本身造輪子,並且日誌的顯示窗口須要常開,建議使用單例模式(參考CSDN 或更直接的【CSDN】)。code
參考: