Hello everyone.
I seem to have problem regarding on how to show or technically make the mysql data visible in the qcombobox.
This is how my gui looks like:
qt.png
After I saved the details in each field, the details will be shown in mysql database which in this case I used phpmyadmin (XAMPP).
Then I want to retrieve the data by using FaceID and when I click LOAD DATA button, all the FaceID will be in the combo box. However, the problem is it become like this. I have debug and the data is there, but it did not show in the combo box.
qt2.png
This is my code :
void FormDialog
::on_comboBox_currentIndexChanged(const QString &arg1
) {
connOpen();
Face = ui->comboBox->currentText();
qry.prepare("SELECT * FROM templateinfo WHERE FaceID='"+Face+"'");
if(qry.exec())
{
while(qry.next())
{
ui ->FaceIDLineEdit->setText(qry.value(0).toString());
ui ->nameLineEdit->setText(qry.value(1).toString());
ui ->female->setChecked(qry.value(2).toBool());
ui ->male->setChecked(qry.value(3).toBool());
ui ->WantedlineEdit->setText(qry.value(4).toString());
qDebug() << "execute";
}
connClose();
}
else {
qDebug() << "not execute";
}
}
void FormDialog::on_comboBox_currentIndexChanged(const QString &arg1)
{
connOpen();
Face = ui->comboBox->currentText();
QSqlQuery qry;
qry.prepare("SELECT * FROM templateinfo WHERE FaceID='"+Face+"'");
if(qry.exec())
{
while(qry.next())
{
ui ->FaceIDLineEdit->setText(qry.value(0).toString());
ui ->nameLineEdit->setText(qry.value(1).toString());
ui ->female->setChecked(qry.value(2).toBool());
ui ->male->setChecked(qry.value(3).toBool());
ui ->WantedlineEdit->setText(qry.value(4).toString());
qDebug() << "execute";
}
connClose();
}
else {
qDebug() << "not execute";
}
}
To copy to clipboard, switch view to plain text mode
void FormDialog::on_loadData_clicked()
{
connOpen();
qry->prepare("SELECT FaceID FROM templateinfo");
qry->exec();
modal->setQuery(*qry);
ui->comboBox->setModel(modal);
qry->next();
qDebug() << (modal->rowCount());
}
void FormDialog::on_loadData_clicked()
{
connOpen();
QSqlQueryModel * modal = new QSqlQueryModel();
QSqlQuery* qry = new QSqlQuery(db);
qry->prepare("SELECT FaceID FROM templateinfo");
qry->exec();
modal->setQuery(*qry);
ui->comboBox->setModel(modal);
qry->next();
qDebug() << (modal->rowCount());
}
To copy to clipboard, switch view to plain text mode
Please help me solve this problem as I am new in Qt and I dont know which part is wrong
Bookmarks