[QT] Print on a mainWindow a new QGridLayout

Hi to all, :-)

I'm searching to resolve this problem with QT Creator 4.5.1:

I have a class with a method "print" who refresh the automatic mainWindow of this class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  void class::print()
{
int i=0;

mainLayout = new QGridLayout;

       for (i=0;i<rows;i++)  //rows and columns are private members of class
        {
           for (int j=0;j<columns;j++)
          {
               mainLayout->addWidget(arrayLabel[i][j], i, j);

          }

       }
 mainLayout->addWidget(pushButton,i+1,4);
 mainLayout->addWidget(nameLine,i+1,3);
 setLayout(mainLayout);
}


It create a new QGridLayout and rebuid it any times with new value labels in arrayLabel.
After that sets mainLayout as the layout of automatic QMainWindow of class.

No problem in the first time print() is called.

But the second time the program says:

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

So, can I set a QMainWindow's layout only one time?

I've tried to delete mainLayout before call print(), but program says that mainLayout doesn't exist. I've tried then to declare mainLayout in the class membrers, but it doesn't exist anyway.

What can I do? :-(

Thanks!!
closed account (S6k9GNh0)
You should be able to check and see if mainLayout is equal to NULL and if not, apply. If so, delete and reapply but I thought there was a faster way to do that...

http://doc.trolltech.com/4.5/qlayout.html#QLayout-2

And it iternally checks for multiple layouts and doesn't allow for more than one.
Topic archived. No new replies allowed.