QLayout: Attempting to add QLayout "" to MainWindow "", which already has a layout
======================================================
widget_main_body = new QWidget(this);
setCentralWidget(widget_main_body);
hbox=new QHBoxLayout(this);
widget_main_body->setLayout(hbox);
以上会报:QLayout: Attempting to add QLayout "" to MainWindow "", which already has a layout
的错误。
因为new QHBoxLayout(this)的this参数,会自动把该layout设置给this。
所以处理办法是:
widget_main_body = new QWidget(this);
setCentralWidget(widget_main_body);
hbox=new QHBoxLayout; //这里不传参
widget_main_body->setLayout(hbox);