Hi,

I am trying to put some buttons dynamically into a QGridLayout, that is in a QTabView. Therefore I put that QGridLayout into a tab and fill it with the buttons.
The problem is, that when I add more than 4 Buttons to that layout it changes its parent somwhow and I get an error. The error occurs, when the button shall be added to the layout.
Qt Code:
  1. Error:
  2. parent: QWidget(0x289be8, name = "tabUserSpecificMethods")
  3. parent: QWidget(0x289be8, name = "tabUserSpecificMethods")
  4. parent: QWidget(0x289be8, name = "tabUserSpecificMethods")
  5. parent: QWidget(0x289be8, name = "tabUserSpecificMethods")
  6. parent: QWidget(0x289be8, name = "tabUserSpecificMethods")
  7. parent: screenMeasMeth(0x260830, name = "screenMeasMeth")
  8. QLayout::parentWidget: A layout can only have another layout as a parent.
  9. Segmentation fault
To copy to clipboard, switch view to plain text mode 


my Code looks like that:
Qt Code:
  1. VLaytUserSpecificMethods = new QGridLayout(ui->tabUserSpecificMethods);
  2. VLaytUserSpecificMethods->setHorizontalSpacing(6);
  3. VLaytUserSpecificMethods->setVerticalSpacing(6);
  4. VLaytUserSpecificMethods->setObjectName(QString::fromUtf8("VLaytUserSpecificMethods"));
  5. VLaytUserSpecificMethods->setContentsMargins(10, 15, 0, 0);
  6. VLaytUserSpecificMethods->setGeometry(QRect(0,0,431,490));
  7.  
  8. for(int i = 0; i <= tmpMethodNames.size()-1; i++){
  9. listBtnUserMeasMeth[i] = new QPushButton(this);
  10. listBtnUserMeasMeth[i]->setVisible(true);
  11. listBtnUserMeasMeth[i]->setText(tmpMethodNames.at(i));
  12. listBtnUserMeasMeth[i]->setMaximumSize(QSize(200,55));
  13. listBtnUserMeasMeth[i]->setMinimumSize(QSize(200,55));
  14. listBtnUserMeasMeth[i]->setStyleSheet(globalStyleSheet::btnEnabled);
  15. listBtnUserMeasMeth[i]->setFont(dynamicBtnFont);
  16. listBtnUserMeasMeth[i]->setFocusPolicy(Qt::NoFocus);
  17.  
  18. qDebug() << "parent: " << VLaytUserSpecificMethods->parent();
  19. if(i % 2 == 0){
  20. VLaytUserSpecificMethods->addWidget(listBtnUserMeasMeth[i],c_GridRowCounter,0);
  21. }
  22. else{
  23. VLaytUserSpecificMethods->addWidget(listBtnUserMeasMeth[i],c_GridRowCounter,1);
  24. c_GridRowCounter++;
  25. }
  26. }
  27. VLaytUserSpecificMethods->addItem(VSpacerBtnList,++c_GridRowCounter,0);
To copy to clipboard, switch view to plain text mode 


Does anybody know the reason, why this happens?