PDA

View Full Version : QListWidget string increment



nagabathula
20th December 2010, 06:31
Hello, i am trying to populate a QListWidget with the names Somename_1 to Somename_300.. But the problem is the names start with Somename_300 and decrement down to Somename_1 in the QListWidget.. How can i make it insert from Somename_1 and increment to Somename_300.

for( int i=0 ; i<300; i++ )
{
listWidgetdata += QString("SOmename_%1").arg(i) + (i==299 ? "" : "");",");
}
for(int j=0; j < listWidgetdata.count();j++)
{
QListWidgetItem(item[kfast]->text());
ParamsLW->insertItem(kfast,listWidgetdataat(j)); // kfast =0; at the start of the program
ksast++;
}
ParamsLW is the object name for the QListWidget.
what is going wrong why is the counter starting the names from 300 instead of 1.

thank you

Lykurg
20th December 2010, 08:16
Your code is not working. What about posting the real code? And the best way is a simple loop from 1 to 300 where you add an item at the end.

Also what is item?

nagabathula
20th December 2010, 09:19
hello sir thank you i solved the problem.. it was a very silly mistake kfast was the item number but i incremented ksast i think thats why there was this error. I used the code from some previous post which i found on this forum to auto create incrementing names with numbers. This is what i did now.


for( int i=0 ; i<300; i++ )
{
defineparameters.append(QString("Thermo Couple_%1").arg(i));
}



ParamsLW->insertItem(kfast,listWidgetdataat(j)); // kfast =0;
ksast++; // supposed to be kfast++;

thank you sir problem is solved.