Hi all,

I have this problem which I have been pondering and can't seem to find a solution to it. Therefore, I need some expertise in programming field for help.

I have a group of widget (1 label, 1 combo Box, 1 push button)
this group can populate to n arbitrary number of times base on user requirements.

event involved is just the push button clicked event but I will have to get the text field of both the label and combo box in order to produce the output I want.

the problem in the code below is all button will only display the last group items (label and combo box) but not their own group item which is not a surprise as the pointers will eventually point to the last set.

How can i associate the groups together? Any input would be good.

P.S. I initially though of array of pointers but it will kept my amount of group I can have. or waste some mem from unused pointers.

disp.h
Qt Code:
  1. ...
  2. private slots:
  3. void go_clicked();
  4.  
  5. private:
  6. void createPlace();
  7. QWidget *createCellWidget(group grp);
  8.  
  9. mapinfo map; <-- struct
  10.  
  11. QToolBox *toolbox;
  12. QLabel *grp;
  13. QComboBox *combo
To copy to clipboard, switch view to plain text mode 

disp.cpp
Qt Code:
  1. ...
  2. void disp::createPlace()
  3. {
  4. int i = 0;
  5. QGridLayout *layout = new QGridLayout;
  6.  
  7. foreach (group grp, map.grp) {
  8. layout->addWidget(createCellWidget(grp), i, 0);
  9. i++;
  10. }
  11.  
  12. layout->setRowStretch(i, 10);
  13.  
  14. QWidget *itemWidget = new QWidget;
  15. itemWidget->setLayout(layout);
  16.  
  17. toolbox = new QToolBox;
  18. toolbox->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Ignored);
  19. toolbox->setMinimumWidth(itemWidget->sizeHint().width());
  20. toolbox->addItem(itemWidget,"Select Place");
  21. }
  22.  
  23. QWidget *disp::createCellWidget(group grp)
  24. {
  25. combo = new QComboBox;
  26. foreach (place p, grp.building)
  27. combo->addItem(p.placename);
  28.  
  29. combo->setMaximumWidth(200);
  30.  
  31. btn->setText("Go");
  32. btn->setMaximumWidth(50);
  33.  
  34. grp = new QLabel;
  35. grpname->setText(grp.grpname);
  36.  
  37. QGridLayout *layout = new QGridLayout;
  38. layout->addWidget(grpname, 0, 0);
  39. layout->addWidget(combo, 1, 0);
  40. layout->addWidget(btn,1,1);
  41.  
  42. QWidget *widget = new QWidget;
  43. widget->setLayout(layout);
  44.  
  45. connect(btn, SIGNAL(clicked()), this, SLOT(go_clicked()));
  46.  
  47. return widget;
  48. }
  49.  
  50. void disp::go_clicked()
  51. {
  52. //something with own group's combo text and label text
  53. qDebug() << grpname->text() << " ----- " << combo->currentText(); //testing
  54. }
To copy to clipboard, switch view to plain text mode