Results 1 to 4 of 4

Thread: Custom Deleter for QSharedPointer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    1

    Default Custom Deleter for QSharedPointer

    UPD: It all works as expected, sorry for my mistake. Please, delete or close this topic.

    Hi, all!

    How to specify custom Deleter for QSharedPointer correctly?

    Qt Code:
    1. class A
    2. {
    3. public:
    4. void f() {...}
    5. };
    6.  
    7. ...
    8. QSharedPointer<A> pA1(new A, ???);
    To copy to clipboard, switch view to plain text mode 


    What shall I write instead of ??? in a code above to make QSharedPointer call method f() of object that is about to be deleted? Or it is not possible at all?
    I.e. i want pA1 to call method f() of controlled instance of class A when pA1's reference counter drops to 0. &A::f doesn't seem to work since A::f() is not static and object must be specified.

    But why does the code below always work when A is subclass of QObject?

    Qt Code:
    1. QSharedPointer<A> pA2(new A, &QObject::deleteLater);
    To copy to clipboard, switch view to plain text mode 

    Non-static deleteLater() method of newly created class A instance is called as ref. counter of pA2 drops to 0.

    Thank you in advance && Sorry for my English

    P.S. I use GCC version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5), Qt 4.8.4
    Last edited by hoRUS; 8th May 2013 at 17:08. Reason: updated contents

Similar Threads

  1. Replies: 11
    Last Post: 20th November 2012, 22:18
  2. QSharedPointer / QWeakPointer in QML?
    By centipede in forum Qt Quick
    Replies: 1
    Last Post: 23rd May 2012, 09:25
  3. inserting to Qlist of QSharedPointer
    By jajdoo in forum Newbie
    Replies: 1
    Last Post: 11th August 2011, 00:20
  4. emitting QSharedPointer
    By babu198649 in forum Newbie
    Replies: 11
    Last Post: 26th July 2010, 08:51
  5. Problem with QSharedPointer
    By weaver4 in forum Newbie
    Replies: 2
    Last Post: 19th April 2010, 14:22

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.