1
我工作的一些Qt
應用,其主窗口由QPlainTextEdit
子類日誌窗口輸出事件。我有三種類型的消息:QRegExp編譯時警告
- 信息消息,其表示
QString
與[INFO]
子 - 警告消息,該消息表示
QString
與[WARNING]
子 - 錯誤消息,其表示
QString
開始開始開始[ERROR]
子串
現在,我想用QSyntaxHighlighter
級是根據其類型來改變這些消息的顏色(信息型 - Qt::DarkBlue
顏色,警告型 - Qt::DarkYellow
顏色,錯誤型 - Qt::DarkRed
顏色),這裏是代碼塊,這應該已經完成了任務:
void UeLogWindowTextHighlighter::ueSetupRules()
{
UeHighlightRule* ueRuleInfo=new UeHighlightRule(this);
UeHighlightRule* ueRuleWarning=new UeHighlightRule(this);
UeHighlightRule* ueRuleError=new UeHighlightRule(this);
this->ueInfoStartExpression()->setPattern("^[INFO].\*"); // FIRST WARNING
this->ueWarningStartExpression()->setPattern("^[WARNING].\*"); // SECOND WARNING
this->ueErrorStartExpression()->setPattern("^[ERROR].\*"); // THIRD WARNING
this->ueInfoExpressionCharFormat()->setForeground(Qt::darkGray);
this->ueWarningExpressionCharFormat()->setForeground(Qt::darkYellow);
this->ueErrorExpressionCharFormat()->setForeground(Qt::darkRed);
ueRuleInfo->ueSetPattern(this->ueInfoStartExpression());
ueRuleInfo->ueSetTextCharFormat(this->ueInfoExpressionCharFormat());
this->ueHighlightRules()->append(ueRuleInfo);
ueRuleWarning->ueSetPattern(this->ueWarningStartExpression());
ueRuleWarning->ueSetTextCharFormat(this->ueWarningExpressionCharFormat());
this->ueHighlightRules()->append(ueRuleWarning);
ueRuleError->ueSetPattern(this->ueErrorStartExpression());
ueRuleError->ueSetTextCharFormat(this->ueErrorExpressionCharFormat());
this->ueHighlightRules()->append(ueRuleError);
} // ueSetupRules
然而,當我編譯項目時,我得到以下警告:
../../../gui/uelogwindowtexthighlighter.cpp: In member function 'void UeLogWindowTextHighlighter::ueSetupRules()': ../../../gui/uelogwindowtexthighlighter.cpp:58:47: warning: unknown escape sequence: '\*' [enabled by default]
this->ueInfoStartExpression()->setPattern("^[INFO].\*");
^../../../gui/uelogwindowtexthighlighter.cpp:59:50: warning: unknown escape sequence: '\*' [enabled by default]
this->ueWarningStartExpression()->setPattern("^[WARNING].\*");
^../../../gui/uelogwindowtexthighlighter.cpp:60:48: warning: unknown escape sequence: '\*' [enabled by default]
this->ueErrorStartExpression()->setPattern("^[ERROR].\*");
^
,因此消息不會着色(這是我的懷疑)。 我的正則表達式有什麼問題?我正在關注this question and answer on SO。