Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions

Find if file exists in QFileSystemModel.



  • Hi
    I want to to create a Folder with mkdir of QFileSystemModel. But I want to create with name "New Folder" and if "New Folder" already exists create "New Folder(1)". So Firstly I want to find out it "New Folder" already exists. How can I find it?
    for now I do

    int count = 0;
    QModelIndex fileIndex = FileModel_ -> index(nameToCheck);
    
     while (FileModel_ -> fileInfo(fileIndex).exists())
        {
          nameToCheck = name + "(" + (++count) + ")";
          fileIndex = FileModel_ -> index(nameToCheck);
        }
    
        FileModel_ -> mkdir(parentDir, nameToCheck);
    

    Where FileModel_ is an object of QFileSystemModel.
    thanks


Log in to reply