[Qt-interest] Is there any way to dynamically rearrange a dialog'slayout?

Ross Bencina rossb-lists at audiomulch.com
Thu May 20 03:46:18 CEST 2010


Hi Ellen

Just a guess, but it sounds like some of your widgets are getting deleted 
when you delete the layouts -- ie, somewhere you have something which is the 
child of something you're deleting which shouldn't be.

The documentation is a bit confusing regarding transfer of ownership in 
different cases (see Layout::addChildWidget, QLayout::addItem, 
QLayout::removeWidget etc). In any case, it's worth keeping in mind that the 
ownership graph(parent/child relationship) is not always the same as the 
layout nesting graph. One thing you could try is to make sure, after 
removing something from a layout, you reset its parent to your Dialog (or to 
NULL), that way it's lifetime won't be tied to anything you care about.

QObject::dumpObjectTree() might be helpful for debugging this.

You could also consider keeping your pointer lists up to date by connecting 
to QObject::destroyed() on each object. Keep in mind that objects may be 
deleted using deleteLater() so this signal isn't always synchronous.

HTH

Ross.

----- Original Message ----- 
From: Ellen Kestrel
To: qt-interest at trolltech.com
Sent: Thursday, May 20, 2010 10:49 AM
Subject: [Qt-interest] Is there any way to dynamically rearrange a 
dialog'slayout?


I have a dialog whose main layout is a QVBoxLayout that contains mostly a 
series of identically structured QHBoxLayouts.  The QHBoxLayouts, and the 
widgets in them, are all stored in lists of QPointers as members of the 
dialog.  I want to make it so that more of these layouts can be added to the 
dialog dynamically, so I made slots that added or removed widgets and 
layouts to and from these lists of pointers (without actually deleting 
anything) and then called an updating function that first removes everything 
from the main layout and deletes any layout items that are not in one of the 
lists of pointers, and then adds everything that is in a list back into the 
main layout.  All of these functions check and recheck for the lists having 
the wrong number of items, having null pointers, etc., and print error 
messages if anything is wrong.  Yet, in addition to the main layout getting 
screwed up and laying out sublayouts on top of other sublayouts, it crashes 
at seemingly random times without printing any of my error messages.  What 
it does print to the terminal begins thusly:

*** glibc detected *** ./ExecutableName: free(): invalid next size (fast): 
0x09778378 ***
======= Backtrace: =========
...

It also constantly prints this message, whether it crashes or not:

QLayout::addChildLayout: layout "" already has a parent

It looks like QLayout::removeItem is not properly removing layouts from 
other layouts.  I did not create any of these layouts with parent widgets, 
since setting the layouts takes care of that.

Again, at every single point where there could be a null pointer to cause a 
crash, *there is error checking*, none of my error messages are ever 
printed, and neither is there a standard segfault message.  Is there any way 
to do this, or should I just give up?

EK




_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest 




More information about the Qt-interest-old mailing list