QT 輸出日誌

2021-09-24 05:16:32 字數 744 閱讀 3722

qtmessagehandler qinstallmessagehandler(qtmessagehandler handler)

qinstallmessagehandler來實現輸出詳細日誌,輸出檔名,行號,所在函式及事件,並寫入檔案。最後呼叫系統原來的函式,使資訊像之前一樣輸出到除錯視窗,便於開發。

qinstallmessagehandler(debug::outputmessage);

靜態函式outputmessage

void debug::outputmessage(qtmsgtype type, const qmessagelogcontext &context, const qstring &msg)

{    qstring logpath = "e:";

static qmutex mutex;

mutex.lock();

qstring text;

switch(type)

{case qtdebugmsg:

text = qstring("debug:");

break;

case qtwarningmsg:

text = qstring("warning:");

break;

case qtcriticalmsg:

text = qstring("critical:");

Qt 日誌輸出

為了方便進行現場除錯,我們需要使用日誌記錄我們關心的資料資訊,而qt提供了日誌系統非常方便,只需要我們提供乙個函式指標即可,定義如下 void mymessagehandler qtmsgtype,const qmessagelogcontext const qstring 通常,實現如下 void...

qt日誌實現

qt的日誌有四個級別 qdebug 除錯資訊 qwarning 警告資訊 qcritical 嚴重錯誤 qfatal 致命錯誤 可以通過下的 void qcritical const char msg,void qdebug const char msg,void qfatal const char...

Qt 日誌檔案

qt 列印資訊等級 型別描述 qdebug 除錯資訊 qinfo 一般資訊 qwarning 警告資訊 qcritical 危險資訊 qfatal 致命資訊 注 使用qfatal列印資訊後,程式會終止 自定義日誌輸出資訊 qtmessagehandler qinstallmessagehandler...