选择估计组合框,日期和时间

时间:2014-03-27 18:50:10

标签: c++ qt qt4 qt5

我想选择ComboBox的内容,以及DateEdit TimeEdit 这没用 它只显示mat字段

QSqlQuery qry; 
qry.prepare("select * from Etudiant"); 
if(qry.exec()){ 
    while(qry.next()){ 
        ui->lineEdit_matE->setText(qry.value(0).toString()); 
        ui->comboBox_sexE->setCurrentIndex(qry.value(1).toInt());     
        ui->dateEdit_dateA->setDate(qry.value(2).toDate()); 
        ui->timeEdit_heureA->setTime(qry.value(3).toTime()); 
    }
}

1 个答案:

答案 0 :(得分:0)

QSqlQuery qry; 
qry.prepare("select * from Etudiant"); 
if(qry.exec()){
    if(qry.next) {
       do{ 
            ui->lineEdit_matE->setText(qry.value(0).toString()); 
            ui->comboBox_sexE->setCurrentIndex(qry.value(1).toInt());     
            ui->dateEdit_dateA->setDate(qry.value(2).toDate()); 
            ui->timeEdit_heureA->setTime(qry.value(3).toTime()); 
        }while(qry.next());   
    }
    else {
    qDebug << "No results found.";
    }


}
else
{
  qDebug << "Unable to execute query."
}

您将看到它是否返回值。