Results 1 to 3 of 3

Thread: General destroy question

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default General destroy question

    Hi,

    I have a class that looks like this:

    Qt Code:
    1. struct moduleFieldDef
    2. {
    3. QString code;
    4. QString description;
    5. QVariant value;
    6. QVariant previousValue;
    7. };
    8.  
    9. typedef moduleFieldDef TmoduleFieldDef;
    10.  
    11. class fieldInColModel : public QAbstractTableModel
    12. {
    13. Q_OBJECT
    14. public:
    15. fieldInColModel(QObject *parent=0);
    16. ~fieldInColModel();
    17.  
    18. private:
    19. QList<TmoduleFieldDef> m_fields;
    20. };
    To copy to clipboard, switch view to plain text mode 

    In the implementation m_fields gets filled with a series of fields some of them with a valid * to a delegate. Both the class and the * to delegates share the same parent (a QDialog).

    Now, when the class gets destroyed what happens to the list m_fields, the fields it contains and the valid * to a delegates? Do the valid * to a delegates gets destroyed too? or they will get destroy after (when its parent gets destroyed)?

    Thanks,
    Carlos.

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: General destroy question

    If you ask if the delegates get destroyed,when m_fields is destroyed, the answer is "no".
    Don't write a post just to thank someone, use "Thanks" button.

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

    qlands (16th September 2011)

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: General destroy question

    As I've posted in your other thread, someday you will regret such thing:
    Qt Code:
    1. struct moduleFieldDef
    2. {
    3. ...
    4. };
    To copy to clipboard, switch view to plain text mode 
    What if you pass this pointer to a view and it gets deleted ? You are left with dangling pointer. I think its better safe than sorry :
    Qt Code:
    1. struct moduleFieldDef
    2. {
    3. ...
    4. QPointer<QAbstractItemDelegate> delegate;
    5. };
    To copy to clipboard, switch view to plain text mode 
    QPointer

Similar Threads

  1. Drag and Drop General Question
    By onurozcelik in forum Qt Programming
    Replies: 0
    Last Post: 19th August 2010, 15:22
  2. Passing plain text to function general question
    By vieraci in forum General Programming
    Replies: 3
    Last Post: 24th October 2009, 20:30
  3. General question about events overriding
    By mattc in forum Qt Programming
    Replies: 2
    Last Post: 14th September 2009, 16:35
  4. General Question about Qt4 Model/View
    By reed in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2008, 16:06
  5. Replies: 1
    Last Post: 24th June 2006, 21:55

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.