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):
taskData td2;
QList<condition_struct*> *conditions2 = new QList<condition_struct*>;
QList<QList<condition_struct*>* > *tasks2 = new QList<QList<condition_struct*>* >;
condition_struct *cnd2 = new condition_struct;
cnd2->stateDWord = 1;
cnd2->td_current.zone_id = 2;
conditions2->push_back(cnd2);
cnd2 = new condition_struct;
cnd2->stateDWord = 3;
cnd2->td_current.zone_id = 4;
conditions2->push_back(cnd2);
tasks2->push_back(conditions2);
cnd2 = new condition_struct;
cnd2->stateDWord = 5;
cnd2->td_current.zone_id = 6;
conditions2->push_back(cnd2);
cnd2 = new condition_struct;
cnd2->stateDWord = 7;
cnd2->td_current.zone_id = 8;
conditions2->push_back(cnd2);
cnd2 = new condition_struct;
cnd2->stateDWord = 9;
cnd2->td_current.zone_id = 10;
conditions2->push_back(cnd2);
tasks2->push_back(conditions2);
//...
condition_struct *cndCr = new condition_struct;
QList<condition_struct*> *conditionsCr = new QList<condition_struct*>;
printf("tasks2 vector size: %d\n\n",tasks2->size());
for(QList<QList<condition_struct*>* >::iterator ti0=tasks2->begin();ti0!=tasks2->end();ti0++)
{
printf("conditions2 vector size: %d\n\n", (*ti0)->size());
for(QList<condition_struct*>::iterator ci0=(*ti0)->begin();ci0!=(*ti0)->end();ci0++)
{
cndCr->stateDWord = (*ci0)->stateDWord;
cndCr->td_current.zone_id = (*ci0)->td_current.zone_id;
printf("stateDWord: %d, zone_id: %d\n",cndCr->stateDWord,cndCr->td_current.zone_id);
(*ci0)->stateDWord = cndCr->stateDWord;
(*ci0)->td_current.zone_id = cndCr->td_current.zone_id;
}
}
taskData td2;
QList<condition_struct*> *conditions2 = new QList<condition_struct*>;
QList<QList<condition_struct*>* > *tasks2 = new QList<QList<condition_struct*>* >;
condition_struct *cnd2 = new condition_struct;
cnd2->stateDWord = 1;
cnd2->td_current.zone_id = 2;
conditions2->push_back(cnd2);
cnd2 = new condition_struct;
cnd2->stateDWord = 3;
cnd2->td_current.zone_id = 4;
conditions2->push_back(cnd2);
tasks2->push_back(conditions2);
cnd2 = new condition_struct;
cnd2->stateDWord = 5;
cnd2->td_current.zone_id = 6;
conditions2->push_back(cnd2);
cnd2 = new condition_struct;
cnd2->stateDWord = 7;
cnd2->td_current.zone_id = 8;
conditions2->push_back(cnd2);
cnd2 = new condition_struct;
cnd2->stateDWord = 9;
cnd2->td_current.zone_id = 10;
conditions2->push_back(cnd2);
tasks2->push_back(conditions2);
//...
condition_struct *cndCr = new condition_struct;
QList<condition_struct*> *conditionsCr = new QList<condition_struct*>;
printf("tasks2 vector size: %d\n\n",tasks2->size());
for(QList<QList<condition_struct*>* >::iterator ti0=tasks2->begin();ti0!=tasks2->end();ti0++)
{
printf("conditions2 vector size: %d\n\n", (*ti0)->size());
for(QList<condition_struct*>::iterator ci0=(*ti0)->begin();ci0!=(*ti0)->end();ci0++)
{
cndCr->stateDWord = (*ci0)->stateDWord;
cndCr->td_current.zone_id = (*ci0)->td_current.zone_id;
printf("stateDWord: %d, zone_id: %d\n",cndCr->stateDWord,cndCr->td_current.zone_id);
(*ci0)->stateDWord = cndCr->stateDWord;
(*ci0)->td_current.zone_id = cndCr->td_current.zone_id;
}
}
To copy to clipboard, switch view to plain text mode
When running this code, I got the following output:
tasks2 vector size: 2
conditions2 vector size: 5
stateDWord: 1, zone_id: 2
stateDWord: 3, zone_id: 4
stateDWord: 5, zone_id: 6
stateDWord: 7, zone_id: 8
stateDWord: 9, zone_id: 10
conditions2 vector size: 5
stateDWord: 1, zone_id: 2
stateDWord: 3, zone_id: 4
stateDWord: 5, zone_id: 6
stateDWord: 7, zone_id: 8
stateDWord: 9, zone_id: 10
tasks2 vector size: 2
conditions2 vector size: 5
stateDWord: 1, zone_id: 2
stateDWord: 3, zone_id: 4
stateDWord: 5, zone_id: 6
stateDWord: 7, zone_id: 8
stateDWord: 9, zone_id: 10
conditions2 vector size: 5
stateDWord: 1, zone_id: 2
stateDWord: 3, zone_id: 4
stateDWord: 5, zone_id: 6
stateDWord: 7, zone_id: 8
stateDWord: 9, zone_id: 10
To copy to clipboard, switch view to plain text mode
instead of something like
tasks2 vector size: 2
conditions2 vector size: 2
stateDWord: 1, zone_id: 2
stateDWord: 3, zone_id: 4
conditions2 vector size: 3
stateDWord: 5, zone_id: 6
stateDWord: 7, zone_id: 8
stateDWord: 9, zone_id: 10
tasks2 vector size: 2
conditions2 vector size: 2
stateDWord: 1, zone_id: 2
stateDWord: 3, zone_id: 4
conditions2 vector size: 3
stateDWord: 5, zone_id: 6
stateDWord: 7, zone_id: 8
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.
Bookmarks