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. QFileSystemModel setNameFilters working as expected in Linux, not Windows
Forum Updated to NodeBB v4.3 + New Features

QFileSystemModel setNameFilters working as expected in Linux, not Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.8k 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.
  • P Offline
    P Offline
    Procyon
    wrote on last edited by
    #1

    I have a QListView with a QFileSystemModel. I have a way to allow people to enter a filter that should trim the list view down to only those files whose name matches the filter. So if my list consists of:

    • Red square.png
    • Blue circle.jpg
    • Green triangle.gif

    and I set the filter to "Blue", I only see Blue circle.jpg in the list. If I set the filter to "square", I only see Red square.png. Set the filter to "gif", I only see Green triangle.gif.

    My code is working perfectly as expected in Linux. It does absolutely nothing in Windows. I've Googled this matter up and down, and can't find any insight. Here's a bit of the relevant code:

    In the MainWindow constructor:

            filemodel = new QFileSystemModel;
            filemodel->setFilter(QDir::Files);
            filemodel->setRootPath("/");
    
            fileView = new QListView;
            fileView ->setModel(filemodel);
            fileView ->setRootIndex(filemodel->index(pathToFiles));
    

    And the public slot method applying the filter:

    void MainWindow::filterFilterView()
    {
        QStringList filterToApply;
        filterToApply.append("*" + filterText->text() + "*");
    
        filemodel->setNameFilters(filterToApply);
        filemodel->setNameFilterDisables(false);
    
        fileView->setModel(filemodel);
    }
    

    Like I said, works great in Linux, does nothing in Windows. Can anyone shed some light? Thanks very much in advance.

    kshegunovK 1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      Long shot here, but does your windows Qt possibly have QT_NO_REGEXP set? That would disable the use of setNameFilters according to the Qt function.

      One thing to test to verify is call setNameFilters then call nameFilters to see if there are any results. If it's empty then you probably built with or have QT_NO_REGEXP set somewhere.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      4
      • P Offline
        P Offline
        Procyon
        wrote on last edited by Procyon
        #3

        Thanks for the reply. When I call nameFilters at the bottom of filterFilterView(), I get back the same thing that I put into it. So for example, if I put "red" into filterText, fileView->nameFilters will return "* red *" (without the spaces). I tried to look up QT_NO_REGEXP in the qt documentation, but could find no reference to it, so I'm unsure how to check if it's set, or how to change the setting. Any advice here?

        A 1 Reply Last reply
        0
        • P Procyon

          I have a QListView with a QFileSystemModel. I have a way to allow people to enter a filter that should trim the list view down to only those files whose name matches the filter. So if my list consists of:

          • Red square.png
          • Blue circle.jpg
          • Green triangle.gif

          and I set the filter to "Blue", I only see Blue circle.jpg in the list. If I set the filter to "square", I only see Red square.png. Set the filter to "gif", I only see Green triangle.gif.

          My code is working perfectly as expected in Linux. It does absolutely nothing in Windows. I've Googled this matter up and down, and can't find any insight. Here's a bit of the relevant code:

          In the MainWindow constructor:

                  filemodel = new QFileSystemModel;
                  filemodel->setFilter(QDir::Files);
                  filemodel->setRootPath("/");
          
                  fileView = new QListView;
                  fileView ->setModel(filemodel);
                  fileView ->setRootIndex(filemodel->index(pathToFiles));
          

          And the public slot method applying the filter:

          void MainWindow::filterFilterView()
          {
              QStringList filterToApply;
              filterToApply.append("*" + filterText->text() + "*");
          
              filemodel->setNameFilters(filterToApply);
              filemodel->setNameFilterDisables(false);
          
              fileView->setModel(filemodel);
          }
          

          Like I said, works great in Linux, does nothing in Windows. Can anyone shed some light? Thanks very much in advance.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Procyon said in QFileSystemModel setNameFilters working as expected in Linux, not Windows:
          Remove this line:

          fileView->setModel(filemodel);
          

          and move this:

          filemodel->setNameFilterDisables(false);
          

          to where you set up the model. Test like this.
          Make sure you have not defined QT_NO_REGEXP if you compiled Qt yourself for the windows build.

          Read and abide by the Qt Code of Conduct

          P 1 Reply Last reply
          4
          • P Procyon

            Thanks for the reply. When I call nameFilters at the bottom of filterFilterView(), I get back the same thing that I put into it. So for example, if I put "red" into filterText, fileView->nameFilters will return "* red *" (without the spaces). I tried to look up QT_NO_REGEXP in the qt documentation, but could find no reference to it, so I'm unsure how to check if it's set, or how to change the setting. Any advice here?

            A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            @Procyon Yea it would only have been if you built your Qt and defined it somewhere or one of your options defined it. If you have a binary install of qt it won't apply. It was a long shot.

            Next up I would throw it in the debugger and single step through each line of code as it is executed to see what parts are skipped on windows that are executed on linux.

            I'd test it out but I don't have a windows Qt setup at the moment. I could test linux or mac but of course the issue is in windows (like always .... I hate windows, lol).

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            2
            • kshegunovK kshegunov

              @Procyon said in QFileSystemModel setNameFilters working as expected in Linux, not Windows:
              Remove this line:

              fileView->setModel(filemodel);
              

              and move this:

              filemodel->setNameFilterDisables(false);
              

              to where you set up the model. Test like this.
              Make sure you have not defined QT_NO_REGEXP if you compiled Qt yourself for the windows build.

              P Offline
              P Offline
              Procyon
              wrote on last edited by
              #6

              @kshegunov I gave that a shot, no change.

              @ambershark Yeah, I installed QT through the installer as opposed to compiling it. But I will download the source and step through it to see what I can find.

              Thanks very much for your help.

              A 1 Reply Last reply
              1
              • P Procyon

                @kshegunov I gave that a shot, no change.

                @ambershark Yeah, I installed QT through the installer as opposed to compiling it. But I will download the source and step through it to see what I can find.

                Thanks very much for your help.

                A Offline
                A Offline
                ambershark
                wrote on last edited by
                #7

                @Procyon Good luck, let us know what you find out in case someone else has this issue later on. :)

                If I get a chance I will install Windows/Qt and give it a test too. I'll report back here as well.

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                1 Reply Last reply
                2

                • Login

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