Results 1 to 2 of 2

Thread: How to store custom data inside each index in QFileSystemModel

  1. #1
    Join Date
    Nov 2015
    Posts
    41
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to store custom data inside each index in QFileSystemModel

    Hi,

    I have QFileSystemModel and I want to store some additional data in each index.
    I used setData function like as

    Qt Code:
    1. model.setData(index, "additional data", Qt::UserRole);
    To copy to clipboard, switch view to plain text mode 

    but when I try take these custom data by means of command

    Qt Code:
    1. qDebug()<< model.index(0, 0, parent).data(Qt::UserRole);
    To copy to clipboard, switch view to plain text mode 

    it return invalid QVariant, why? QFileSystemModel does not contain container for custom data? If not then I have to inherit from file system model and store it myself?

    For example inside my custom delegate if index represents file I need take size of that file. If index represents folder I want take count of files inside this folder and some more information. How I can this done?

    Regards,

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to store custom data inside each index in QFileSystemModel

    Quote Originally Posted by Scope View Post
    it return invalid QVariant, why? QFileSystemModel does not contain container for custom data?
    I doubt that the model can store data, its purpose is to present the file system data in the Qt model interface.

    Quote Originally Posted by Scope View Post
    If not then I have to inherit from file system model and store it myself?
    That sounds like a valid approach.
    Alternatively you could use a QIdentityProxyModel based proxy

    Cheers,
    _

Similar Threads

  1. QFileSystemModel and custom column / data
    By ArnSpin in forum Newbie
    Replies: 4
    Last Post: 2nd March 2015, 12:07
  2. QFileSystemModel: creating custom rows of data
    By masterlaws in forum Qt Programming
    Replies: 3
    Last Post: 12th August 2013, 11:58
  3. Replies: 13
    Last Post: 10th April 2013, 06:15
  4. Replies: 9
    Last Post: 14th February 2013, 19:39
  5. QFileSystemModel::remove not removing index from model
    By revorgm in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 09:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.