执行时(没有编译错误)我进入控制台
QWidget::setLayout: 试图在 CGSearchResult "" 上设置 QLayout "",它已经有一个布局
我正在使用以下代码:
CGSearchResult::CGSearchResult(QWidget *parent) : QWidget(parent)
{
initControls();
SetTableContent();
}
void CGSearchResult::initControls()
{
backButton = new QPushButton(tr("&Back"));
connect(backButton, SIGNAL(clicked()), this, SLOT(showHome()));
model=new QStandardItemModel();
QWidget::setFont(QFont("Courier New", 8, QFont::Bold));
searchTable = new QTableView(this);
searchTable->showGrid();
searchTable->resize(720,400);
searchTable->horizontalHeader()->setDefaultSectionSize(170);
searchTable->verticalHeader()->setDefaultSectionSize(50);
searchTable->verticalHeader()->hide();
searchTable->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
searchTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QGridLayout *layout = new QGridLayout();
layout->addWidget(backButton, 0, 0, 1, 1);
layout->addWidget(searchTable, 2, 0, 1, 1);
setLayout(layout);
}