错误
QWidget::setLayout: Attempting to set QLayout "" on PreviewWindow "", which already has a layout
错误原因
QMainWindow本身有布局
错误解决方法
QMainWindow布局已经有,应该是工具栏,菜单栏,中心窗口等等,我们实际想添加控件其实是想添加进中心窗口,修改代码如下:
PreviewWindow::PreviewWindow(QWidget *parent) : QMainWindow(parent) { _pTextBrowser = new QTextBrowser(this); QWidget *pWidget = new QWidget(this); QHBoxLayout *pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(_pTextBrowser); pWidget->setLayout(pLayout); setCentralWidget(pWidget); setWindowTitle(tr("帮助")); setGeometry(QRect(200, 200, 800 ,800)); }