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: fileName works, filePath and fileInfo crashes
Forum Updated to NodeBB v4.3 + New Features

QFileSystemModel: fileName works, filePath and fileInfo crashes

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

    Hi!

    I have a crash occuring with QFileSystemModel when I call filePath
    Here is my code :

    Constructor:
    @
    fileSystemModel = new QFileSystemModel; //those are declared in a class and this is the constructor
    proxyModel = new QSortFilterProxyModel;
    QModelIndex rootModelIndex = fileSystemModel->setRootPath("Tracks/");

    proxyModel->setSourceModel(fileSystemModel);
    proxyModel->setFilterKeyColumn(2);
    proxyModel->setFilterRegExp("Folder|xml");
    @

    Here is the slot function for when an element is clicked within the TreeView. Index is the parameter given by the TreeView signal
    @
    // This works :
    qDebug() << fileSystemModel->fileName(index);

    // This crashes :
    qDebug() << fileSystemModel->filePath(index);

    qDebug() << fileSystemModel->fileInfo(index); //crashes too
    @

    Using Qt 4.8 on Linux Mint with Qt Creator.
    Does any of you have any idea of what I could have been doing wrong ?

    Thanks a lot :)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexisdm
      wrote on last edited by
      #2

      Just to be sure, the view shows the proxy model ?
      If it is the case, you should convert the index you are receiving to an index belonging to the source model with proxyModel->mapToSource(index)

      The reason the fileName call works, is because it doesn't check that the index is valid, but simply returns the Qt::DisplayRole role.
      filePath checks that the model of the index is the same as the one the function is called from but with an assertion, so it crashes and fileInfo calls _filePath, so it crashes to.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        doom_Oo7
        wrote on last edited by
        #3

        YES! You saved my life. Works perfectly.
        I suspected that it might be due to the different indexes, however I didn't know how to match them.
        Thanks a lot for the explanation :)

        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