I am trying to add two items into my QListWidget dynamically. However, the following codes only allow me to add only the last item into the list. strList.size() contains 4 items. Assuming name contains "ABC 1" and "ABC 2".

Is my loop incorrect? Or is my method of adding items into the listWidget wrong?

.h:

Qt Code:
  1. public:
  2. QListWidgetItem *item[2];
To copy to clipboard, switch view to plain text mode 

.cpp:

Qt Code:
  1. int num = 0;
  2. for(int i = 0; i < strList.size(); i++)
  3. {
  4. if(strList[i] == "ABC")
  5. {
  6. ...
  7.  
  8. item[num] = new QListWidgetItem();
  9. item[num]->setText(name);
  10. ui.listWidget->insertItem(num, item[num]);
  11. num += 1;
  12. }
  13. }
To copy to clipboard, switch view to plain text mode 

Output (listWidget):

ABC 2
Expected output (listWidget):

ABC 1
ABC 2