QRegExp 编译时警告
QRegExp compile time warnings
我正在开发一些 Qt
应用程序,其 main window 由 QPlainTextEdit
subclassed log window 用于输出事件。我有三种类型的消息:
- 信息消息,表示一个以
[INFO]
开头的QString
子串
- 警告消息,表示以
[WARNING]
子字符串 开头的 QString
- 错误信息,表示一个以
[ERROR]
子串 开头的QString
现在,我想用 QSyntaxHighlighter
class 实现的是根据消息的类型更改这些消息的颜色(INFO 类型 - Qt::DarkBlue
颜色,WARNING 类型 - Qt::DarkYellow
颜色,ERROR 类型 - 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。
星级 (*
) 不必转义。删除 \
或者如果你需要 \
它应该被转义并且 写双 \
(\
)。
我正在开发一些 Qt
应用程序,其 main window 由 QPlainTextEdit
subclassed log window 用于输出事件。我有三种类型的消息:
- 信息消息,表示一个以
[INFO]
开头的QString
子串 - 警告消息,表示以
[WARNING]
子字符串 开头的 - 错误信息,表示一个以
[ERROR]
子串 开头的
QString
QString
现在,我想用 QSyntaxHighlighter
class 实现的是根据消息的类型更改这些消息的颜色(INFO 类型 - Qt::DarkBlue
颜色,WARNING 类型 - Qt::DarkYellow
颜色,ERROR 类型 - 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。
星级 (*
) 不必转义。删除 \
或者如果你需要 \
它应该被转义并且 写双 \
(\
)。