Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. About filter file name in Qt
Forum Updated to NodeBB v4.3 + New Features

About filter file name in Qt

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 3 Posters 7.2k Views 1 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.
  • D Offline
    D Offline
    dleviathan
    wrote on 19 Dec 2011, 07:52 last edited by
    #1

    I have just problem as:
    I want filter all file have shape: "Exc1.zip" "Exc2.zip" v...v.. from a folder have many file.
    my code follow :
    @
    QRegExp re;
    re.setPatternSyntax(QRegExp::Wildcard);
    if(sTenThuMuc == "Challenge")
    {
    re.setPattern("Exc([0-9]{1,1}).zip");
    }
    else if(sTenThuMuc == "HangMan")
    {
    re.setPattern("hangman([0-9]+).zip");
    }
    @
    then in filter filename:
    @ QString sFilter = re.pattern();
    QStringList slFilters;
    slFilters << sFilter;
    qDir.setNameFilters(slFilters);
    QFileInfoList lFileInfo = qDir.entryInfoList();@

    plz help me!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 19 Dec 2011, 08:03 last edited by
      #2

      Documentation states, that ::setNameFilters() understands wildcards, not full regular expressions.

      So, pass QString("Exc?.zip") to qDir.setNameFilters(), and then filter out files you need manually using QRegExp.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 19 Dec 2011, 08:08 last edited by
        #3

        You are making it way to difficult. You are trying to use a full-blown regular expression, but QDir only understands simply wildcard matching:

        @
        QStringList filter;
        if(sTenThuMuc == "Challenge")
        {
        filter << "Exc?.zip";
        }
        else if(sTenThuMuc == "HangMan")
        {
        filter << "hangman*.zip";
        }

        // use the filter
        slFilters << sFilter;
        qDir.setNameFilters(filters);
        QFileInfoList lFileInfo = qDir.entryInfoList();
        //check if the returned file names actually match what you were after, because the filter matches more than just numbers at the wildcard positions!
        @

        1 Reply Last reply
        0

        1/3

        19 Dec 2011, 07:52

        • Login

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