Results 1 to 2 of 2

Thread: remove QVBoxLayout content in QHBoxLayout

  1. #1
    Join Date
    Jul 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default remove QVBoxLayout content in QHBoxLayout

    Hi!

    I have a QHBoxLayout in which I store QVBoxLayout, but I want to delete at any given time. For this use the following method:

    if (layerH)// QHBoxLayout
    {
    while(layerH->takeAt(0) != 0)
    {
    layerH->removeItem(layerH->takeAt(0));
    delete layerH->takeAt(0);
    }
    }

    The problem is that after executing this function the QVBoxLayout are still present.

    any idea how to fix this?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: remove QVBoxLayout content in QHBoxLayout

    Follow your code:
    your first line in the while() loop removes the first item in the layout - but you don't store the pointer to the removed item (which is also a memory leak), and now the first item is the next item.
    Then, in the second line, you are deleting the current first item, which due to the first line is actually the second item.
    So you are deleting every second item, and removing every first.
    And please use code tags.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 19th March 2011, 10:57
  2. How to remove Space Between 2 QHBoxLayout Widget
    By jaya in forum Qt Programming
    Replies: 3
    Last Post: 6th October 2010, 22:57
  3. QHBoxLayout & QVBoxLayout
    By damodharan in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2010, 14:13
  4. Problem with QHBoxlayout & QVBoxlayout
    By phillip_Qt in forum Qt Tools
    Replies: 5
    Last Post: 13th January 2009, 10:26
  5. QVBoxLayout and QHBoxLayout problem
    By fmariusd in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2009, 20:58

Tags for this Thread

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.