View Full Version : Upper limit on number of widgets?

29th September 2008, 21:41
I have a complex application that shows a representation of information from a database. For each element in the database, I create a hierarchy of widgets - images, push buttons, scrollable editable text and so on. There are probably at least a dozen subwidgets for each of these elements - potentially more depending on the exact contents of the element.

The problem occurs when I have a *lot* of these elements. I eventually get a series of QWidget::create: failed to create window (cannot create a top level child window) messages. I've traced this back to QWidgetPrivate::create_sys line 419 (this is Qt 4.2.2), where there is a failure to a call to CreateWindowExA. This causes all sorts of havoc, as parts of my hierarchy of widgets (mostly the text widgets) are painted over the upper left corner of my application. Both the application and, unfortunately, the debugger, become useless at this point, and I have to kill the app.

-widgetcount tells me that I have 35 widgets left, with a max of 8258. It certainly looks like I've run out of widgets. Is there an upper limit on the number of widgets? All of my widgets are properly parented in a nice hierarchy, so I don't understand why it would want new top level widgets. Is there something I can do to consume fewer of these resources?

Help! I don't want to try to rewrite my complex hierarchy. There are some simplifications I can make, but that seems like it will only buy me some larger upper bound. Any ideas?

30th September 2008, 00:00
Use newer version of Qt. Since 4.4 the number of widgets shouldn't be limited in any way due to use of Aliens. An alternative is to implement your hierarchy using items and not widgets. Having 8000 widgets in a single window is madness ;)