Quote Originally Posted by freiza View Post
Question 1) Is there any way that I can pass "qstr" instead of "qstr[k]" and still it prints out everything correctly in tableview? I mean a structure that can be passed directly to set data such that I don't have to use for loop?
Question 2) Instead of append can I populate qstr using "qstr << "hello"<<"world"<<"this"<<"is"<<"cool"<<"qt";"
Question 3) How to use foreach loop instead of for loop in above case?
1) No, not if you use QStandardItemModel. If you subclass QAbstractItemModel, you can implement the model using whatever container type you desire.

2) Yes, of course.

3) See below:

Qt Code:
  1. int i = 0;
  2.  
  3. foreach (str, qstr)
  4. {
  5. int row = i / model.columnCount();
  6. int col = i % model.columnCount();
  7. QModelIndex index = model.index(row, col);
  8. model.setData(index, str);
  9. i++;
  10. }
To copy to clipboard, switch view to plain text mode