Results 1 to 3 of 3

Thread: QDirModel subclassing and private data member

  1. #1
    Join Date
    May 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QDirModel subclassing and private data member

    Hi, I would appreciate some help on the following:

    I have a class named ThumbnailDirModel (subclass of QDirModel) with an additional role (ThumbnailRole). A custom delegate (ThumbnailItemDelegate) can call the data() member function of the ThumbnailDirModel to get a QPixmap and render it in a View.
    (the pixmap is the actual content of the image file to be rendered).
    Everything works fine until I tried to implement a container of Pixmap for the purpose of avoiding recreating a pixmap from a file everytime it is needed.
    I tought the logical place for the container would be a private data member in ThumbnailDirModel as the model is responsible for providing all the data.
    So when a request for a thumbnail is made via data() the model checks if it is present in the container, if not the container loads it from the file...
    And there it is ! data() is const and does not allow the container expansion (non const)
    In a general sense: how a model internal data can update itself when a request for data is made to the model ?
    And/Or in a pratical sense: what is wrong with my design ?

    Thanks
    jej

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDirModel subclassing and private data member

    You can mark the member variable as 'mutable' or const_cast<ThumbnailDirModel*>(this).
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    jej (26th May 2009)

  4. #3
    Join Date
    May 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QDirModel subclassing and private data member

    Whoua, I missed the basics i guess.
    Thanks a lot....
    jej

Similar Threads

  1. Replies: 1
    Last Post: 20th May 2009, 20:36

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.