Question

I have a list of QRegExp objects which are created in one part of the application, and used at some other part. They are created like:

struct HighlightingRule
{
    QRegExp pattern;
    // somoe more stuff... 
};

QStringList keywordPatterns;
for(int i=0; i<keywords.size(); i++)
{
    QString t = QString("\\b") + keywords.at(i).toUpper() + QString("\\b");
    keywordPatterns.append(t);
}

foreach (const QString &pattern, keywordPatterns)
{
    rule.pattern = QRegExp(pattern);
    highlightingRules.append(rule);
}

and used like:

foreach (const HighlightingRule &rule, highlightingRules) 
{
    QRegExp expression(rule.pattern);
    // do something with it
}

and in the place where I use it I would like to see the "pattern" of the expression I'm trying to use ...

How can I print a QRegExp?

Était-ce utile?

La solution

Try this:

qDebug() << expression.pattern();

Returns the pattern string of the regular expression. The pattern has either regular expression syntax or wildcard syntax, depending on patternSyntax().

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top