1.背景
1. 软件版本:qt4.8.4
2. 在QMainWindow 中添加一个layout 后 会报
Debugging starts
QLayout: Attempting to add QLayout "" to Frmbattery "", which already has a layout
2.参考网络教程
Qt:Attempting to add QLayout “” to MainWindow “”, which already has a layout
3. 测试测试结果
按照教程参考代码来,还是会报错。红色圈里面的this 要去掉,就不会了。
实际代码
this->resize(800, 600);
battery = new Battery();//
battery->setValue(20);
battery->resize(600,400);
batteryQSlider = new QSlider();
connect(batteryQSlider,SIGNAL(valueChanged(int)),battery,SLOT(setValue(int)));
batteryQSlider->setValue(20);
widget = new QWidget;
batteryqvboxlayout=new QVBoxLayout(this) ;
batteryqvboxlayout->addWidget(battery);
batteryqvboxlayout->addWidget(batteryQSlider);
widget->setLayout(batteryqvboxlayout);
setCentralWidget(widget);