Hi, I don't how to use the values from spinboxes that are dynamically created at runtime. I want to get the current value in the spinboxes when I click a push button.

Here's what I've done so far:
Qt Code:
  1. QFileInfo checkFile(Path_to_DB);
  2.  
  3. if(checkFile.isFile())
  4. {
  5. if(db.open())
  6. {
  7. qDebug() << "Connected to database file";
  8. }
  9. }else{
  10. qDebug() << "Database file not found";
  11. }
  12.  
  13. int value;
  14. QSqlQuery qry;
  15.  
  16. if (qry.exec("SELECT name FROM customer"))
  17. {
  18. while(qry.next())
  19. {
  20. qDebug() << qry.value(0).toString();
  21. if(qry.isValid())
  22. {
  23. QString cust = qry.record().value(0).toString();
  24.  
  25. //create widgets
  26. QLabel *label = new QLabel(QString(cust));
  27. QSpinBox *spinbox = new QSpinBox;
  28. spinbox->setMaximum(3);
  29. label->setGeometry(0,0,80,41);
  30.  
  31. //add to VBoxLayout
  32. ui->verticalLayout->addWidget(label);
  33. ui->verticalLayout->addWidget(spinbox);
  34. value = spinbox->value(); // value is always going to be zero here
  35. qDebug() << value;
  36. }
  37. }
  38. }
  39. else
  40. {
  41. qDebug() << qry.lastError();
  42. }
  43. }
  44.  
  45. MainWindow::~MainWindow()
  46. {
  47. delete ui;
  48. }
  49.  
  50. void MainWindow::on_pushButton_clicked()
  51. {
  52. //get spinbox values
  53. if(!db.isOpen()){
  54. qDebug() << "No connection to db";
  55. return;
  56. }
  57. int value2;
  58. value2 = spinbox->value2();
  59. qDebug() << value2;
  60.  
  61. //save values to db
  62. ............
To copy to clipboard, switch view to plain text mode 

Thanks in advance!

--