我对编程很陌生。我想将单选按钮的值插入 SQLite 数据库,但仍然找不到正确的方法。该程序包含 9 个单选按钮,分别是 1-3、4-5、6-7 和 8-9 4 个不同的分组/布局。谢谢你。
void lifestyle::on_pushButton_3_clicked()
{
QSqlQuery myqry;
myqry.prepare("CREATE TABLE IF NOT EXISTS Lifestyle (Drinking VARCHAR(15), "
"Exercise VARCHAR(15), Smoking VARCHAR(10), Diet VARCHAR(10)) ");
if(!myqry.exec())
qDebug()<<myqry.lastError();
else
qDebug()<<"Table Created!";
QString drinking= ui->radioButton_1->text();
QString exercise = ui->radioButton_5->text();
QString smoking = ui->radioButton_7->text();
QString diet = ui->radioButton_8->text();
myqry.prepare("INSERT INTO Lifestyle(Drinking, Exercise, Smoking, Diet) "
"values('"+drinking+"','"+exercise+"','"+smoking+"','"+diet+"')");
if(myqry.exec()){
ui->labelstat->setText("The information has been saved");
}
else{
ui->labelstat->setText("Information failed to saved");
}
}