Results 1 to 2 of 2

Thread: Delete Layout and its childs

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Delete Layout and its childs

    Hi, another problem... :S

    I have a QScrollArea with a layout set.

    In execution, I create some checkboxes, that I add to the lyout.

    Qt Code:
    1. QCheckBox* pChk = 0;
    2. for(int i = 0; i < myList.count(); ++i)
    3. {
    4. pChk = new QCheckBox(info);
    5. my_Lyout->addWidget(pChk);
    6. }
    To copy to clipboard, switch view to plain text mode 


    I have the

    ui.my_scrollArea->setLayout(my_Lyout);

    in the constructor.

    I'd like to destroy all the checkboxes when the destructor is called:

    Qt Code:
    1. CAddGroup::~CAddGroup()
    2. {
    3. for(int i = 0; i < my_Lyout->count(); ++i)
    4. {
    5. QLayoutItem* pChk = my_Lyout->itemAt(i);
    6. delete pChk;
    7. pChk = 0;
    8. }
    9.  
    10. delete(ui.my_scrollArea->layout());
    11.  
    12. m_pVLayGroups = 0;
    13. }
    To copy to clipboard, switch view to plain text mode 

    But delete(ui.m_srcUsers->layout()); gives me an out of memory exception.

    any idea?

    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Delete Layout and its childs

    You should use QScrollArea::setWidget() to set the widget on the scroll area and then you can just delete this widget and its children (the checkboxes) will be deleted as well.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    jano_alex_es (11th May 2009)

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.