I am very new to programming.
I wanted to insert the values of my radiobutton into sqlite database but still doesn't found the right way to do it.
The program consist 9 radiobutton, which is 1-3,4-5,6-7 and 8-9 in 4 different grouping/layout.
Thank you.

test.PNG

Qt Code:
  1. void lifestyle::on_pushButton_3_clicked()
  2. {
  3. QSqlQuery myqry;
  4.  
  5. myqry.prepare("CREATE TABLE IF NOT EXISTS Lifestyle (Drinking VARCHAR(15), "
  6. "Exercise VARCHAR(15), Smoking VARCHAR(10), Diet VARCHAR(10)) ");
  7. if(!myqry.exec())
  8. qDebug()<<myqry.lastError();
  9. else
  10. qDebug()<<"Table Created!";
  11.  
  12. QString drinking= ui->radioButton_1->text();
  13. QString exercise = ui->radioButton_5->text();
  14. QString smoking = ui->radioButton_7->text();
  15. QString diet = ui->radioButton_8->text();
  16.  
  17. myqry.prepare("INSERT INTO Lifestyle(Drinking, Exercise, Smoking, Diet) "
  18. "values('"+drinking+"','"+exercise+"','"+smoking+"','"+diet+"')");
  19.  
  20. if(myqry.exec()){
  21. ui->labelstat->setText("The information has been saved");
  22.  
  23. }
  24. else{
  25. ui->labelstat->setText("Information failed to saved");
  26.  
  27. }
  28. }
To copy to clipboard, switch view to plain text mode