| Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
Hi! I'm experiencing some really weird behaviour with menu bars since I switched to the Jambi beta. Sometimes some menus do not appear at all in the first QMainWindow the application is opening, sometimes others suddenly vanish from the menu bar when a second QMainWindow is opened. The behaviour for all of this is surprisingly indeterministic. According to the devblog the garbage collection has become more aggressive and I think that this is the root cause, but as far as I can see the affected objects are all referenced from somewhere: the QAction classes for the menu bar are referenced from an array in my code and the menu items are all in a hierarchy referenced by the QMainWindow instance (otherwise they wouldn't appear in the menu at all, would they?), so they shouldn't be garbage collected as far as I can see. I'd be thankful for some hints to hunt this one down properly. Regards, Gregor -- [ signature omitted ]
Attachment:
pgpemqUOBj3IJ.pgp
Description: PGP signature
Hi, Gregor. Gregor Mückl wrote: >I'm experiencing some really weird behaviour with menu bars since I switched >to the Jambi beta. Sometimes some menus do not appear at all in the first >QMainWindow the application is opening, sometimes others suddenly vanish from >the menu bar when a second QMainWindow is opened. The behaviour for all of >this is surprisingly indeterministic. > > I'm trying to reproduce this, but have not had any luck so far. Any more information you have or examples that exhibit this behavior would be very helpful :-) I'll get back to you when I find out anything. -- Eskil
Hi again, Gregor.
Gregor Mückl wrote:
> According to the devblog the garbage collection has become more aggressive
>and I think that this is the root cause, but as far as I can see the affected
>objects are all referenced from somewhere: the QAction classes for the menu
>bar are referenced from an array in my code and the menu items are all in a
>hierarchy referenced by the QMainWindow instance (otherwise they wouldn't
>appear in the menu at all, would they?), so they shouldn't be garbage
>collected as far as I can see. I'd be thankful for some hints to hunt this
>one down properly.
>
>
Could you try passing a parent to the QMenu() constructor when you are
creating the menus? We will make an effort to handle cases like this
properly by default, but as a general rule it's currently good style to
give QObjects and QWidgets parents when you construct them, unless you
specifically want them to be top levels or short lived objects. This is
because not all functions that keep references to objects actually
reparent them, and we are, as of now, not handling every such case as
well as we'd like to.
On a related note: We are also considering removing the default parent
of "null" in all these constructors to help avoid confusion like this.
This means that you will never write:
QWidget w = new QWidget();
to get a top level widget, but will have to tell Jambi more explicitly
that you want the widget to be a top-level:
QWidget w = new QWidget(null);
Anyone have any opinions on that?
-- Eskil
On Monday 12 February 2007, Eskil A. Blomfeldt wrote: > Hi again, Gregor. > > Gregor Mückl wrote: > > According to the devblog the garbage collection has become more > > aggressive and I think that this is the root cause, but as far as I can > > see the affected objects are all referenced from somewhere: the QAction > > classes for the menu bar are referenced from an array in my code and the > > menu items are all in a hierarchy referenced by the QMainWindow instance > > (otherwise they wouldn't appear in the menu at all, would they?), so they > > shouldn't be garbage collected as far as I can see. I'd be thankful for > > some hints to hunt this one down properly. > > Could you try passing a parent to the QMenu() constructor when you are > creating the menus? We will make an effort to handle cases like this > properly by default, but as a general rule it's currently good style to > give QObjects and QWidgets parents when you construct them, unless you > specifically want them to be top levels or short lived objects. This is > because not all functions that keep references to objects actually > reparent them, and we are, as of now, not handling every such case as > well as we'd like to. > I've tried and this seems to fix the issue. I was not properly parenting QAction and QMenu objects. Thank you very much! > > On a related note: We are also considering removing the default parent > of "null" in all these constructors to help avoid confusion like this. > This means that you will never write: > > QWidget w = new QWidget(); > > to get a top level widget, but will have to tell Jambi more explicitly > that you want the widget to be a top-level: > > QWidget w = new QWidget(null); > > Anyone have any opinions on that? > > -- Eskil Enforcing a parent seems like a good idea in general. However, it may not always be possible to know the parent of a widget when it is constructed. I cannot say if these situations can be avoided alltogether by careful design. But allowing for construction without a known parent and reparenting to the proper parent later on would open the same loophole that exists now, I think. Messing around with this seems tricky to me. Regards, Gregor -- [ signature omitted ]
Attachment:
pgp3wPZObK665.pgp
Description: PGP signature