Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:31:17+00:00 2026-06-14T18:31:17+00:00

I have 2 tree views in my .ui. One treeview is DriveView and other

  • 0

I have 2 tree views in my .ui. One treeview is DriveView and other is DriveListView. Now I have written a code which displays the drives of my system in `DriveView. I have done it as follows:

// Gets called when application starts
void DetailView::onCamStartup()
{
   m_SystemModel = new QFileSystemModel(this);
   m_SystemListViewModel = new QFileSystemModel(this);
   m_SystemModel->setRootPath(QDir::currentPath());
   ui->DriveView->setModel(m_SystemModel);
   ui->DriveListView->setModel(m_SystemListViewModel);

   // regard less how many columns you can do this using for:
   for(int nCount = 1; nCount < m_SystemModel->columnCount(); nCount++)
      ui->DriveView->hideColumn(nCount);
}

Now once i click a particular drive in my DriveView it shows me the subfolders inside it. What i basically need to do is to iterate/traverse the entire drive and search for .mp3 files inside. Basically check all folders and subfolders for it. Once it locates the files, it should display them in my another Treeview i.e. DriveListView. I have written a following code for it:

void DetailView::on_DriveView_clicked(const QModelIndex &index)
{
QString sPath = m_SystemModel->fileInfo(index).absoluteFilePath();
ui->DriveListView->setRootIndex(m_SystemListViewModel->setRootPath(sPath));

m_SystemModel->setRootPath(QDir::currentPath());
m_SystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs );
m_SystemListViewModel->setFilter( QDir::Files | QDir::NoDotAndDotDot );

QStringList m_list;
QDirIterator dirIt(sPath,QDirIterator::Subdirectories);

while (dirIt.hasNext())
{
    dirIt.next();
    if (QFileInfo(dirIt.filePath()).isFile())
    {
        if (QFileInfo(dirIt.filePath()).suffix() == "mp3")
        {
            qDebug()<<dirIt.filePath();
            m_list<<dirIt.filePath();
            m_list.append(dirIt.filePath());
        }
    }

    QStringListModel *model = new QStringListModel();
    model->setStringList(m_list);
    m_SystemListViewModel->setNameFilterDisables(false);
}
}

Whenever I click the subfolders which have mp3 files, it displays them in treeview. This is were I am facing the problem. When I click the mail folder, nothing gets displayed. Ideally I want to display all the mp3 files present in main folder and its subfolders to be displayed. I have put qDebug()<<dirIt.filePath(); and when i run the app and click a drive, this prints me all the .mp3 files in Application Output but it doesnt display them in the treeview i.e. DriveListView.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:31:19+00:00Added an answer on June 14, 2026 at 6:31 pm

    Since you are iterating over all subdirs manually anyway, try using a QStringListModel for m_SystemListViewModel. This way, you can directly display m_list in the view. See http://qt-project.org/doc/qt-4.8/qstringlistmodel.html

    Alternatively, it looks like a QSortFilterProxyModel might be used to filter the displayed results in the list view, but I have never used it. See http://qt-project.org/doc/qt-4.8/qsortfilterproxymodel.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project, I have TreeView, which contains a tree of objects of various
So I have a TreeView like the one below, with certain items being hidden.
I have 2 forms. in form 1, I have a treeview. in one method,
I'm using MVVM to bind views to objects in a Tree. I have a
I have a tree view <asp:TreeView ID=TreeView1 runat=server DataSourceID=SiteMapDataSource1 ShowExpandCollapse=False> </asp:TreeView> As you can
i have an ASP tree view having a Node so now, i have to
I have a tree view which has a folder icon by default and once
I have a tree view on the left side. Selecting a node displays relevant
I currently have a simple tree view that contains one parent node with multiple
Hello All I am using infragsitics tree view control.I have one stored procedure that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.