Do you get some warnings about mainWindow allready have a layout?

Try to add a QWidget *test = new QWidget(0); make it the parent of the layout QVBoxLayout* layout = new QVBoxLayout(test); and setCentralWidget(test);