Results 1 to 14 of 14

Thread: Removing widget from layout

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Removing widget from layout

    Hello,

    I'd like to remove a widget from the layout and delete it.

    for this I'd like to use the following source code

    ...
    int cnt;
    QLayoutItem *it;
    MyWidget *w;

    cnt = aVLayout->count();

    for( int i = 0; i < cnt; i++ )
    {
    it = aVLayout->itemAt(0);
    w = ((MyWidget *)(it->widget()));
    aVLayout->removeWidget( w );
    delete w;
    aVLayout->removeItem( it );
    delete it; // SEGMENTATION VIOLATION CRASH!!!
    }

    My questions:
    - Is it necessary to remove and delete the QLayoutItem item?
    - how to do it to avoid the crash?

    In my understanding, the QLayoutItem has been created and added, when the addWidget() method has been called, so when I am removing a widget from the layout and deleting it, also the QLayoutItem shall be removed and deleted. Is it correct?

    I am using Qt 4.6.3

    Thx for your help
    Last edited by lotek; 17th July 2011 at 13:18.

Similar Threads

  1. Replies: 8
    Last Post: 5th May 2021, 16:41
  2. mainwindow layout vs widget layout
    By fatecasino in forum Newbie
    Replies: 2
    Last Post: 14th December 2010, 14:45
  3. (Solved) Removing (replacing) central widget
    By frenk_castle in forum Newbie
    Replies: 7
    Last Post: 14th December 2010, 10:02
  4. How to change a widget to other widget in layout?
    By Kevin Hoang in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2010, 10:55
  5. removing child widget
    By db in forum Newbie
    Replies: 1
    Last Post: 16th August 2007, 12:19

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.