Hello,
In my code I am calling a void-function which creates some variables. However it will crash if I use it like this:
Boxes();
emod.verticalLayout->addWidget(boxes[0]);
emod.verticalLayout->addWidget(boxes[1]);
emod.verticalLayout->addWidget(boxes[2]);
emod.verticalLayout->addWidget(boxes[3]);
emod.verticalLayout->addWidget(boxes[4]);
Boxes();
emod.verticalLayout->addWidget(boxes[0]);
emod.verticalLayout->addWidget(boxes[1]);
emod.verticalLayout->addWidget(boxes[2]);
emod.verticalLayout->addWidget(boxes[3]);
emod.verticalLayout->addWidget(boxes[4]);
To copy to clipboard, switch view to plain text mode
If I use this:
qDebug() << "a1";
Boxes();
qDebug() << "a2";
emod.verticalLayout->addWidget(boxes[0]);
emod.verticalLayout->addWidget(boxes[1]);
emod.verticalLayout->addWidget(boxes[2]);
emod.verticalLayout->addWidget(boxes[3]);
emod.verticalLayout->addWidget(boxes[4]);
qDebug() << "a1";
Boxes();
qDebug() << "a2";
emod.verticalLayout->addWidget(boxes[0]);
emod.verticalLayout->addWidget(boxes[1]);
emod.verticalLayout->addWidget(boxes[2]);
emod.verticalLayout->addWidget(boxes[3]);
emod.verticalLayout->addWidget(boxes[4]);
To copy to clipboard, switch view to plain text mode
It does not crash.
Function boxes() in the header:
public:
void Boxes();
public:
void Boxes();
To copy to clipboard, switch view to plain text mode
the code of boxes() is:
void TableEditor::Boxes(){
boxes.clear();
int x;
for(int i=0;i<15;i++){ //create 15 qcheckboxes;
temp->setObjectName("");
if(x < mod.size()){
qDebug() << "added text" << mod[x];
temp->setText(mod[x]);
temp->setVisible(true);
x++;
}else{
temp->setText("");
temp->setVisible(true);
}
boxes.append(temp);
}
}
void TableEditor::Boxes(){
boxes.clear();
int x;
for(int i=0;i<15;i++){ //create 15 qcheckboxes;
QCheckBox *temp = new QCheckBox(Dialog);
temp->setObjectName("");
if(x < mod.size()){
qDebug() << "added text" << mod[x];
temp->setText(mod[x]);
temp->setVisible(true);
x++;
}else{
temp->setText("");
temp->setVisible(true);
}
boxes.append(temp);
}
}
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.
Bookmarks