PDA

View Full Version : Cant get QMainWindow().centralwidget....



tonnot
7th December 2011, 13:50
QMainWindow().centralWidget() always gives me zero ....
I need to access to this widget from any point on my app...
What I'm doing bad ? Thanks.

Oleg
7th December 2011, 14:15
You getting central widget of new QMainWidget instance, obviously it is empty. Call centralWidget() of your QMainWidget subclass (often it's called MainWidget). To access something through all application you can use, for example, singleton.

ChrisW67
8th December 2011, 00:49
QMainWindow().centralWidget() always gives me zero ....
As Oleg says, the central widget of a default constructed QMainWindow is not likely to be useful. Further, you seem to be expecting QMainWindow::centralWidget() to be static: it isn't and cannot reasonably be so.

I need to access to this widget from any point on my app...
Provide public functions that provide the interface for external entities to operate on the private UI widgets of the main window. Generally these functions will provide a controlled way to achieve some higher level abstract effect and not a mechanism to violate encapsulation.

What I'm doing bad ? Thanks.
Probably perpetuating a bad design.