I have mainList of type Qlist<QStringList>
to which a set 5 of QStringLists named newList is being added. The 7th index of a QStringList named List has an integer value( price). For each of the 5 iterations I want to increase the price value by 10.
i.e the 1st newList has a value of 110 in the 7th index, 2nd newList has a value of 120 in the 7th index, and the the last(5th) newList should have a value 150.
void MainWindow::on_pushButton_clicked()
{
int Price;
Price=100;
for(int i=0;i<5;i++){
for(int j=0;j<List.size();j++){
if(j==7){
Price+=10;
QString priceString=QString::number(Price);
newList<<priceString;
}
else{
newList<<List[j];
}
}
mainList<<newList;
}
ui->label->setText(mainBuyList[0][7]);
ui->label_2->setText(mainBuyList[1][7]);
ui->label_3->setText(mainBuyList[2][7]);
ui->label_4->setText(mainBuyList[3][7]);
ui->label_5->setText(mainBuyList[4][7]);
}
But when I click the button all the labels print only 110! How can I correct this issue?
You must clear newList after mainList<<newList;