Guest User

Untitled

a guest
Nov 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <QList>
  2. #include <QDebug>
  3.  
  4. int main(int argc, char *argv[]) {
  5.  
  6. QList<QList<int>> my_list;
  7.  
  8. int result;
  9. for (int i = 0; i < 2; ++i) {
  10. for (int j = 0; j < 4; ++j) {
  11. result = i * j;
  12. my_list.value(i).push_back(result);
  13. qDebug() << my_list.size() << "," << my_list.value(i).size() << " : " << my_list.value(i).value(j);
  14. }
  15. }
  16.  
  17. return 0;
  18. }
  19.  
  20. Starting C:Users ... buildreleasename_of_the_app.exe...
  21. 0 , 0 : 0
  22. 0 , 0 : 0
  23. 0 , 0 : 0
  24. 0 , 0 : 0
  25. 0 , 0 : 0
  26. 0 , 0 : 0
  27. 0 , 0 : 0
  28. 0 , 0 : 0
  29. C:Users ... buildreleasename_of_the_app.exe exited with code 0
  30.  
  31. my_list.value(i).push_back(result);
  32.  
  33. for (int i = 0; i < 2; ++i) {
  34. my_list.push_back(QList<int>()); // first appends a new QList at index `i`
  35.  
  36. for (int j = 0; j < 4; ++j) {
  37. result = i * j;
  38. my_list[i].push_back(result); // safely retrieves QList at index `i` and adds an element
  39. }
  40. }
Add Comment
Please, Sign In to add comment