Hello,
In my code I am calling a void-function which creates some variables. However it will crash if I use it like this:
Qt Code:
  1. Boxes();
  2. emod.verticalLayout->addWidget(boxes[0]);
  3. emod.verticalLayout->addWidget(boxes[1]);
  4. emod.verticalLayout->addWidget(boxes[2]);
  5. emod.verticalLayout->addWidget(boxes[3]);
  6. emod.verticalLayout->addWidget(boxes[4]);
To copy to clipboard, switch view to plain text mode 
If I use this:
Qt Code:
  1. qDebug() << "a1";
  2. Boxes();
  3. qDebug() << "a2";
  4. emod.verticalLayout->addWidget(boxes[0]);
  5. emod.verticalLayout->addWidget(boxes[1]);
  6. emod.verticalLayout->addWidget(boxes[2]);
  7. emod.verticalLayout->addWidget(boxes[3]);
  8. emod.verticalLayout->addWidget(boxes[4]);
To copy to clipboard, switch view to plain text mode 
It does not crash.

Function boxes() in the header:
Qt Code:
  1. public:
  2. void Boxes();
To copy to clipboard, switch view to plain text mode 

the code of boxes() is:
Qt Code:
  1. void TableEditor::Boxes(){
  2. boxes.clear();
  3. int x;
  4. for(int i=0;i<15;i++){ //create 15 qcheckboxes;
  5. QCheckBox *temp = new QCheckBox(Dialog);
  6. temp->setObjectName("");
  7.  
  8. if(x < mod.size()){
  9. qDebug() << "added text" << mod[x];
  10. temp->setText(mod[x]);
  11. temp->setVisible(true);
  12. x++;
  13. }else{
  14. temp->setText("");
  15. temp->setVisible(true);
  16. }
  17.  
  18. boxes.append(temp);
  19. }
  20. }
To copy to clipboard, switch view to plain text mode 
boxes is a QLIST<QCheckbox*>. and mod is a QLIST<QString>.
What can I do to solve this. I do not want to use qDebug() to fix the function. Could somebody tell me what is wrong and how I can solve this?
any help would be appreciated.