I am having a QMap through which I iterate. I would like to display the keys and values in my QTableWidget.


Qt Code:
  1. int counter=0;
  2. QMapIterator<QChar,int> iter(ArithmeticCoding::letters_freq);
  3. while(iter.hasNext()){
  4. iter.next();
  5. QTableWidgetItem *item0=new QTableWidgetItem(iter.key());
  6. ui->table->setItem(counter,0,item0);
  7.  
  8. QTableWidgetItem *item1=new QTableWidgetItem(iter.value());
  9. ui->table->setItem(counter,1,item1);
  10. counter++;
  11. }
To copy to clipboard, switch view to plain text mode 

Of course here my pointers to QTableWidgetItem get lost resulting in random garbage in my table. What would be the proper way of using them? Should I save them to an additional array? That seems like an overhead to me.