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. [SOLVED] QDir setNameFilter problem, it does not filter
Qt 6.11 is out! See what's new in the release blog

[SOLVED] QDir setNameFilter problem, it does not filter

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.6k 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.
  • E Offline
    E Offline
    endhck
    wrote on last edited by
    #1

    I try to list only .cpp file, so I used setNameFilter but anything was changed, it still lists all files.

    @QDir dir;
    QStringList filters;
    filters << "*.cpp" ;
    dir.setNameFilters(filters);

    QString text = QFileDialog::getOpenFileName(this,
    tr("Open File"),dir.currentPath());@

    Where I am wrong?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      You not needed QDir for filters:

      @
      QString text = QFileDialog::getOpenFileName(this, tr("Open File"),QDir::currentPath(), "Sources (*.cpp)");
      @

      See: http://doc.qt.nokia.com/4.7/qfiledialog.html#getOpenFileName for more examples

      --
      Vasiliy

      1 Reply Last reply
      0
      • E Offline
        E Offline
        endhck
        wrote on last edited by
        #3

        It is worked, thanks

        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