Hi,
I am new to the programming world,
I have trouble in finding a way to put the value of the Combobox into my database.
here's my coding. it is miserable.

Qt Code:
  1. void background::on_pushButton_3_clicked()
  2. {
  3.  
  4. QString name, age,/*gender, pregnant,*/ weight, height/* family*/;
  5. name=ui->lineEdit_name->text();
  6. age=ui->lineEdit_age->text();
  7. QString gender=ui->comboBox_gender->currentText();
  8. QString pregnant=ui->comboBox_pregnant->currentText();
  9. weight=ui->lineEdit_weight->text();
  10. height=ui->lineEdit_height->text();
  11. QString family=ui->comboBox_family->currentText();
  12.  
  13. QSqlQuery myqry;
  14. myqry.prepare("INSERT INTO background(Name, Age, Gender, Pregnant, Weight, Height, Family) values('"+name+"','"+age+"','"+gender+"','"+pregnant+"','"+weight+"','"+height+"','"+family+"')");
  15.  
  16. if(myqry.exec()){
  17. ui->labelstat->setText("The information has been saved");
  18. // QMessageBox::information(this, "Save", "The information has been saved");
  19. }
  20. else{
  21. ui->labelstat->setText("Information failed to saved");
  22. // QMessageBox::warning(this, "Failed", "Information failed to saved");
  23.  
  24. }
  25. }
To copy to clipboard, switch view to plain text mode