Please nominate your Qt Champions for 2021!

Filtering QStringList with QRegExp is not working[SOLVED]

  • Hey,

    I tried to filter a QStringList having entries like these:


    For me just the part 20150718 is interesting.
    So I used the expression QRegExp(^pic20150718.+) to filter.
    If I now use the indexOf-method of QStringList I always get "-1".

    What is the problem with that?
    Thank you very much :-)

  • Lifetime Qt Champion


    Can you show your code ?

    Using strList.indexOf(QRegExp("^pic20150718.*")); works correctly.

    On a side note, if you are using Qt 5, you should rather use QRegularExpression

  • Thank you very much :-)

    First I tried to insert the expression like this:

    QString date = "20150718";
    QString expr = "^pic"+date+".*";
    QRegExp exp(expr);

    This was not working, but now it works.
    I cleaned the whole project and it seems like there was something wrong with the building process :-)

Log in to reply