QWidget::setLayout: Attempting to set QLayout "" on MainWindow "", which already has a layout

如题,出现这个的原因是,如果你的窗口继承的是QMainwindow,需要设置

setCentralWidget();

如下:

     
     
     
     
  1. QWidget * widget = new QWidget (mainWindow );
  2. widget ->setLayout (gridLayout );
  3. mainWindow ->setCentralWidget (widget );
设置好一个widget即可 from:http://blog.csdn.net/zhuyingqingfen/article/details/6562246

你可能感兴趣的:(layout,qt,widget)