PDA

View Full Version : setCentralWidget problems



tlerner
17th October 2009, 01:26
Setup: Qt 4.4.3, using visual studio 2005

I have an app ui file (which is empty) and I want to add another centralWidget UI file on top of it (so when I maximize I can have a black background in my app ui and my centralWidget UI can be center screen. I am trying to use setCentralWidget() for this. If I explained things correctly, is this the path I want to follow? I cant even get a button to display in the central widget:



QApp::QApp(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
CentralWidget cw;
QPushButton b;
b.setGeometry(20,20,20,20);
b.setEnabled(true);//.show();
setCentralWidget( &b );
}


Any help is appreciated. Thank you!

john_god
17th October 2009, 04:01
You should not declare cw and b in the constructor and in the stack, declare them in the class and in the heap, as pointers, because they get out of scope when then constructor method ends.


CentralWidget *cw = new CentralWidget;
QPushButton *b = new QPushButton;

tlerner
19th October 2009, 21:26
Doh! What a n00b error. Thanks for the help!