Results 1 to 4 of 4

Thread: QList<QList > question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2007
    Posts
    4
    Thanks
    2

    Default QList<QList > question

    Hello all,

    I'm trying to create a 2-dimensional QList of some structure.

    Here's the test code (contents of condition struct isn't important, both stateDWord and zone_id variables are int):
    Qt Code:
    1. taskData td2;
    2. QList<condition_struct*> *conditions2 = new QList<condition_struct*>;
    3. QList<QList<condition_struct*>* > *tasks2 = new QList<QList<condition_struct*>* >;
    4.  
    5. condition_struct *cnd2 = new condition_struct;
    6. cnd2->stateDWord = 1;
    7. cnd2->td_current.zone_id = 2;
    8. conditions2->push_back(cnd2);
    9. cnd2 = new condition_struct;
    10. cnd2->stateDWord = 3;
    11. cnd2->td_current.zone_id = 4;
    12. conditions2->push_back(cnd2);
    13.  
    14. tasks2->push_back(conditions2);
    15.  
    16. cnd2 = new condition_struct;
    17. cnd2->stateDWord = 5;
    18. cnd2->td_current.zone_id = 6;
    19. conditions2->push_back(cnd2);
    20. cnd2 = new condition_struct;
    21. cnd2->stateDWord = 7;
    22. cnd2->td_current.zone_id = 8;
    23. conditions2->push_back(cnd2);
    24. cnd2 = new condition_struct;
    25. cnd2->stateDWord = 9;
    26. cnd2->td_current.zone_id = 10;
    27. conditions2->push_back(cnd2);
    28.  
    29. tasks2->push_back(conditions2);
    30.  
    31. //...
    32.  
    33. condition_struct *cndCr = new condition_struct;
    34.  
    35. QList<condition_struct*> *conditionsCr = new QList<condition_struct*>;
    36.  
    37. printf("tasks2 vector size: %d\n\n",tasks2->size());
    38. for(QList<QList<condition_struct*>* >::iterator ti0=tasks2->begin();ti0!=tasks2->end();ti0++)
    39. {
    40. printf("conditions2 vector size: %d\n\n", (*ti0)->size());
    41. for(QList<condition_struct*>::iterator ci0=(*ti0)->begin();ci0!=(*ti0)->end();ci0++)
    42. {
    43. cndCr->stateDWord = (*ci0)->stateDWord;
    44. cndCr->td_current.zone_id = (*ci0)->td_current.zone_id;
    45. printf("stateDWord: %d, zone_id: %d\n",cndCr->stateDWord,cndCr->td_current.zone_id);
    46. (*ci0)->stateDWord = cndCr->stateDWord;
    47. (*ci0)->td_current.zone_id = cndCr->td_current.zone_id;
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 

    When running this code, I got the following output:
    Qt Code:
    1. tasks2 vector size: 2
    2.  
    3. conditions2 vector size: 5
    4.  
    5. stateDWord: 1, zone_id: 2
    6. stateDWord: 3, zone_id: 4
    7. stateDWord: 5, zone_id: 6
    8. stateDWord: 7, zone_id: 8
    9. stateDWord: 9, zone_id: 10
    10.  
    11. conditions2 vector size: 5
    12.  
    13. stateDWord: 1, zone_id: 2
    14. stateDWord: 3, zone_id: 4
    15. stateDWord: 5, zone_id: 6
    16. stateDWord: 7, zone_id: 8
    17. stateDWord: 9, zone_id: 10
    To copy to clipboard, switch view to plain text mode 
    instead of something like
    Qt Code:
    1. tasks2 vector size: 2
    2.  
    3. conditions2 vector size: 2
    4.  
    5. stateDWord: 1, zone_id: 2
    6. stateDWord: 3, zone_id: 4
    7.  
    8. conditions2 vector size: 3
    9.  
    10. stateDWord: 5, zone_id: 6
    11. stateDWord: 7, zone_id: 8
    12. stateDWord: 9, zone_id: 10
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong? Thank you in advance for the answer.
    Last edited by SubV; 25th July 2008 at 13:34.

Similar Threads

  1. SQL Question
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 20:36
  2. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 18:49
  3. Replies: 1
    Last Post: 15th March 2007, 21:45
  4. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 15:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.