tags:

views:

367

answers:

3

I am porting an application from Qt3 to Qt4, and need a Qt4 replacement for QApplication::mainWidget() which used to return the top-level widget in Qt3. Does anyone know how to do this in Qt4?

+2  A: 

I think topLevelWidgets() is as close at it can be.

Edit:

Yup. Qt4 added complexity (and power). There is no application wide MainWidget anymore. Many QMainWindows can be created and shown, and hidden, and shown again. This is a good thing, though :) As shoosh noticed, QT3 behaviour can be easily simulated with global variable (yuck!) or QApplication subclass.

wuub
Yeah, I saw this method. But it felt like a step in the wrong direction since it adds complexity. This is so far the only case where I feel that the Qt3 was better than Qt4, and that's why I had to ask. I will leave the question open a little bit longer, but if no one comes up with anything better I will accept your answer. Thanks..
Kristian
Well, you always can keep track of "main widget" yourself, depending on your app.
Eugene
+2  A: 

Technically, any widget initialized with NULL is a top level widget so QApplication shouldn't assume that one of them is better than another.
The way I usually do it is to save a pointer to the "real" main widget somewhere, even a global variable or a singleton and reference it when needed.

shoosh
+1  A: 

I think what you're looking for has been replaced by the QMainWindow class, which does allow you to set a set and get a central widget.

thekidder