gpt4 book ai didi

qt - QWidget::setLayout 错误:正在尝试设置已经有布局的 QLayout [...]

转载 作者:行者123 更新时间:2023-12-01 11:07:29 29 4
gpt4 key购买 nike

执行时(没有编译错误)我进入控制台

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

我正在使用以下代码:

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);


}

最佳答案

http://qt-project.org/doc/qt-4.8/qwidget.html#setLayout

If there already is a layout manager installed on this widget, QWidget won't let you install another. You must first delete the existing layout manager (returned by layout()) before you can call setLayout() with the new layout.

关于qt - QWidget::setLayout 错误:正在尝试设置已经有布局的 QLayout [...],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3850252/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com