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 SetRootPath Not working.
Forum Updated to NodeBB v4.3 + New Features

QFileSystemModel SetRootPath Not working.

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 810 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.
  • C Offline
    C Offline
    Cysis145
    wrote on last edited by
    #1

    Hi guys im trying to make, essentially a restricted folder searching system that will look in a directory specified by a ListWidget, for specific files using a QStringList and applying it as a filter. But despite everything i try the file paths for the QFileSystemModel are not working!

    In the constructor:

     DataPATH = mwHandle->ProjectDir + "/Data/";
    
        mFileDir = new QFileSystemModel(this);
        mFileDir->setRootPath(DataPATH);
        mFileDir->setNameFilters(Filter);
        ui->LV_LocalFiles->setModel(mFileDir);
        ui->LV_LocalFiles->setRootIndex(mFileDir->setRootPath(DataPATH));
    

    The DataPATH string is correct and has the right file path, but for some reason this sets the ListView (LV_LocalFiles) to show my QT project directory, which is completely different to what DataPATH is.

    Now another area which i need to solve, has the exact same problem. This is when i select something from the ListWidget which contains the different Folder Name to search through and then update the ListView to that directory.

    void AssetRepo::on_LW_LocalType_currentTextChanged(const QString &ct)
    {
    
        if (ct == "Meshes"){
    
        }
        if (ct == "Music"){
    
        }
        if (ct == "Sound"){
    
        }
        if (ct == "Textures"){
            Filter.clear();
            Filter << "*.png" << "*.bmp" << "*.dds" << "*.tga";
            QString Path = DataPATH + ct;
            mFileDir->setRootPath(Path);
            ui->LV_LocalFiles->setRootIndex(mFileDir->setRootPath(Path));
            qDebug() << Path + ct;
        }
        if (ct == "Videos"){
    
        }
    }
    

    Note i've only done Textures for now since all the others will be using the same system and no point filling them up with broken code.

    There are several different folders with the idea being that depending on which Item from the QListWidget is selected the QListView will show that folder. But just like before it shows my QT project directory not the directory i specify, i used the qDebug() to make sure that the event was being triggered which it is. I've looked at several examples and i dont understand why mine is being a pain.

    Also on a side note, the reason im using a QListWidget and Not a QTreeView is because i only want these 5 folders to be "veiwable" in the ListView

    Thanks for your help!

    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