3

On execution (no compile error) I get on the console

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

I am using the following code:

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);
}
2
  • Post unmodified source - the snippet you present is obviously incomplete (for example there is no SetTableContent implementation, the model is not set on searchTable). Only then someone will be able to help you. Commented Oct 3, 2010 at 15:47
  • Actully Chalup, I have implemented the setModel method on the SetTableContent method..one more thing this widget is calling from the another class.(QMainWindow). Commented Oct 3, 2010 at 16:03

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

3 Comments

How to find the layout manger already installed or not? Could you please tell me?
Thanks Ronny... I got it.. I used qDeleteAll(myQWidget->children());
I think testing whether layout() != 0 suffices

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.