2016-03-21 110 views
1

我工作的一些Qt應用,其主窗口QPlainTextEdit子類日誌窗口輸出事件。我有三種類型的消息:QRegExp編譯時警告

  1. 信息消息,其表示QString[INFO]
  2. 警告消息,該消息表示QString[WARNING]
  3. 錯誤消息,其表示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

回答

3

明星(*)不必逃脫。刪除\或如果您需要\它應該逃脫和寫雙\\\)。