Results 1 to 3 of 3

Thread: [SOLVED] Automatic children freeing for objects derived from QObject

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Automatic children freeing for objects derived from QObject

    Quote Originally Posted by hickscorp View Post
    will QT handle this itself when "destructing" the parent QTreeWidget?
    Yes, it will:
    Qt Code:
    1. #include <QObject>
    2. #include <QtDebug>
    3.  
    4. class Test : public QObject
    5. {
    6. public:
    7. Test( QObject * parent = 0 ) : QObject( parent ) { qDebug() << "Test::Test()"; }
    8. ~Test() { qDebug() << "Test::~Test()"; }
    9. };
    10.  
    11. int main()
    12. {
    13. Test *t1 = new Test();
    14. Test *t2 = new Test( t1 );
    15.  
    16. delete t1;
    17.  
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Result:
    Test::Test()
    Test::Test()
    Test::~Test()
    Test::~Test()

  2. The following user says thank you to jacek for this useful post:

    hickscorp (6th December 2006)

  3. #2
    Join Date
    Dec 2006
    Posts
    160
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    33
    Thanked 1 Time in 1 Post

    Default Re: Automatic children freeing for objects derived from QObject

    Well...

    Unless i explicitely delete pLocalLister, i never get destructor debug from my objects.
    Let me summarize how they are made:
    Qt Code:
    1. class IFilesLister : public QObject {
    2. Q_OBJECT
    3. public:
    4. IFilesLister(void);
    5. virtual ~IFilesLister(void);
    6. // The following method calls "DoFetchContent" which is virtual...
    7. bool FetchContent(const CNodeDesc& cParent, QObject* pUserData=0);
    8. protected:
    9. virtual bool DoFetchContent(const CNodeDesc& cParent, QObject* pUserData) = 0;
    10. };
    To copy to clipboard, switch view to plain text mode 

    And then:

    Qt Code:
    1. class CFilesLister_File : public IFilesLister {
    2. Q_OBJECT
    3. public:
    4. CFilesLister_File(void);
    5. CFilesLister_File(const QString& cBasePath_p);
    6. virtual ~CFilesLister_File(void);
    7. protected:
    8. virtual bool DoFetchContent(const CNodeDesc& cParent, QObject* pUserData);
    9. };
    To copy to clipboard, switch view to plain text mode 

    So, what am i doing wrong here?

    [EDIT:] Wooops sorry my misstake, my objects don't "register" to their parent
    Sorry for this time.

    Thanks!
    Pierre.
    Last edited by wysota; 7th December 2006 at 00:08. Reason: reformatted to look better

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.