QRegExp not Accepting Modifier Values ?

  • Hi...

    I have a QLineEdit and a QStringList. My String List contains “m/s^2”, “m/min^2”, “m/s^3”, “m/min^3” strings in it (^ denotes the Power of value). My Line Edit should accept only the characters which are present in the StringList.. I solved that and it Works Fine.

    Now, the Problem is, My RegExp is Not Accepting the ^[SHIFT + 6 key]. I cannot enter that power symbol in my QLineEdit. Other characters like "m", "/" are working Fine... Can u plz Suggest me Why this QRegExp not Accepting the Modifier Values?

    Here's my Code:

    @QString regExpression = "(";
    for (int i = 0; i < getStringList()->size(); ++i)
    regExpression.append(getStringList()->at(i) + "|");

    QRegExp rE(regExpression);
    q_LineEdit->setValidator(new QRegExpValidator(rE, this));@

  • replace the last character of the regExpression with ). your currently is | which makes the regexp invalid. you should check the validity of the regexp with rE.isValid(); next time. also for your ^ you should put it in the string like this: "\^" because the ^ sign is interpreted by the QRegExp.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.