I see there is a new class for regular expressions - QRegularExpression
. Is it just a typedef for QRegExp, or a new class, or what? And why do we need it, we al
At least for Qt 4.8. I can give a very practical reason to use QRegularExpressions
instead of QRegExp
:
Do these look dangerous to you?
int index = myQString.indexOf(myQRegExp);
bool okay = myQString.contains(myQRegExp);
Both lines can corrupt your heap, crash or hang your application. I experienced heap corruption and hang with Qt 4.8. The blog post QString::indexOf() versus Qt 4.5 explains that QString::indexOf()
modifies a const QRegExp
object. QString::contains()
inlines QString::indexOf()
so it's the same problem.
If you're stuck with Qt4 and thus QRegExp, you could use
int index = myQRegExp.indexIn(myQString);
bool okay = (myQRegExp.indexIn(myQString) != -1);
in your sources instead. Or patch the Qt Sources.