Good day all.
This post is an addon to a previous one where i had trouble creating the layout but not that is sorted. Here is my problem

I have a list of 3 items that i would like edited "They happen to corrispond to database field in mysql"
The amount of items can change so therefore i dont want to create the form statically then i would have to create 35 forms in stead of just 1 and pass the list to it.

So this is what i have got to create the form "Im not using a ui as it must be dynamic"

.h file
Qt Code:
  1. #ifndef FRM_MAINTENANCE_ALL_H
  2. #define FRM_MAINTENANCE_ALL_H
  3.  
  4. #include <QWidget>
  5. #include <QDialog>
  6. #include <QtGui>
  7. #include <QApplication>
  8. #include <QDebug>
  9. #include <QMessageBox>
  10. #include <QList>
  11.  
  12. class frm_maintenance_all : public QWidget
  13. {
  14. Q_OBJECT
  15. public:
  16. explicit frm_maintenance_all(QWidget *parent = 0);
  17.  
  18. signals:
  19.  
  20. public slots:
  21.  
  22. private slots:
  23. void frm_create(QString tablename);
  24. void btn_process();
  25.  
  26. private:
  27.  
  28.  
  29.  
  30. };
  31.  
  32. #endif // FRM_MAINTENANCE_ALL_H
To copy to clipboard, switch view to plain text mode 

.cpp file
Qt Code:
  1. #include "frm_maintenance_all.h"
  2.  
  3. frm_maintenance_all::frm_maintenance_all(QWidget *parent) :
  4. QWidget(parent)
  5. {
  6. frm_create("test");
  7.  
  8. }
  9.  
  10. void frm_maintenance_all::frm_create(QString tablename)
  11. {
  12.  
  13. QVBoxLayout *myhoz = new QVBoxLayout;
  14. QStringList mylist;
  15. mylist<< "description" << "name" << "id";
  16.  
  17. int i;
  18. QLineEdit *myline;
  19. for(i=1;i<=mylist.length();i++)
  20. {
  21. myline = new QLineEdit;
  22. myline->setText("Text " + QString::number(i)); //just setting text for testing
  23. myhoz->addWidget(myline);
  24. }
  25.  
  26. QPushButton *btn_process_form = new QPushButton;
  27. myhoz->addWidget(btn_process_form);
  28.  
  29. setLayout(myhoz);
  30. btn_process_form->setText(myline->text()); //it set the text to the last loop as expected but would like to be able to choose which box i want
  31. connect(btn_process_form,SIGNAL(clicked()),this,SLOT(btn_process()));
  32.  
  33. setWindowTitle("Test");
  34. show();
  35.  
  36. }
  37.  
  38. void frm_maintenance_all::btn_process()
  39. {
  40. //This does not work (expected to show line 3 option).
  41. qDebug()<< myline->text();
  42.  
  43. //this function fails left uncomented here for reading
  44. QLineEdit* mydyline = parentWidget()->findChild<QLineEdit*>("myline");
  45. qDebug()<< mydyline->text();
  46. // this also fails
  47. QLineEdit* mydyline = parent()->findChild<QLineEdit*>("myline");
  48. qDebug()<< mydyline->text();
  49. // this also fails
  50. QLineEdit* mydyline = findChild<QLineEdit*>("myline");
  51. qDebug()<< mydyline->text();
  52. // this also fails
  53. QLineEdit* mydyline = this->findChild<QLineEdit*>("myline");
  54. qDebug()<< mydyline->text();
  55. //FAILS WITH THIS ERROR
  56. //The program has unexpectedly finished.
  57.  
  58. }
To copy to clipboard, switch view to plain text mode 

So there are 2 things i would like to please know :

1) How can i create a unique id or something for the LineEdit so i can reference it
eg so i could set the push button to line 2's text instead of the last one.

2) How do i then access the values From sub Functions

Help with this regard Will be awsome

Thanks very much