Home > Blockchain >  How not to create temporary QRegularExpression objects
How not to create temporary QRegularExpression objects

Time:02-01

I am getting a warning (in the QtCreator IDE) regarding the code snippet below. The warning is that I should not create temporary QRegularExpression objects; instead use a static QRegularExpression object.

    QRegularExpression re("SEARCHING...",QRegularExpression::CaseInsensitiveOption);
    QRegularExpressionMatch match = re.match(frame);
    if (match.hasMatch()) {

It's not obvious to me...how should I use the QRegular expression instead?

CodePudding user response:

That's a clazy warning message which you can find a description of here. It's just suggesting that you don't want to keep recreating the QRegularExpression every time you enter that function because the expression is always the same. So doing something like this should work:

static QRegularExpression re("SEARCHING...", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = re.match(frame);
if (match.hasMatch()) {
  • Related