2014-03-27 41 views
0

選擇組合框的內容,並DateEdit TimeEdit 這不起作用 只顯示了墊場選擇估算組合框,日期等時間

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()); 
    } 
} 
+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." 
} 

你會看到它是否返回一個值。