QFileSystemModel SetRootPath Not working.



  • 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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.