Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Filtering QStringList with QRegExp is not working[SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Filtering QStringList with QRegExp is not working[SOLVED]

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 767 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RolBri
    wrote on last edited by RolBri
    #1

    Hey,

    I tried to filter a QStringList having entries like these:

    pic20150718_060126.jpg
    pic20150718_060626.jpg
    pic20150718_061126.jpg
    pic20150719_061126.jpg
    

    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 :-)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        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

        R Offline
        R Offline
        RolBri
        wrote on last edited by
        #3

        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 :-)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved