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

 如题,出现这个的原因是,如果你的窗口继承的是QMainwindow,需要设置
setCentralWidget(); 如下:
   
   
   
   
  1. QWidget * widget = new QWidget ( mainWindow ) ;
  2. widget - >setLayout ( yourMainLayout ) ;
  3. mainWindow - >setCentralWidget (widget ) ;
设置好一个widget,将其加入到CentralWidget即可

你可能感兴趣的:(layout)