Results 1 to 4 of 4

Thread: MySql data not shown in QcomboBox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default MySql data not shown in QcomboBox

    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 :

    Qt Code:
    1. void FormDialog::on_comboBox_currentIndexChanged(const QString &arg1)
    2. {
    3.  
    4. connOpen();
    5.  
    6. Face = ui->comboBox->currentText();
    7.  
    8. QSqlQuery qry;
    9.  
    10. qry.prepare("SELECT * FROM templateinfo WHERE FaceID='"+Face+"'");
    11.  
    12. if(qry.exec())
    13. {
    14. while(qry.next())
    15. {
    16. ui ->FaceIDLineEdit->setText(qry.value(0).toString());
    17. ui ->nameLineEdit->setText(qry.value(1).toString());
    18. ui ->female->setChecked(qry.value(2).toBool());
    19. ui ->male->setChecked(qry.value(3).toBool());
    20. ui ->WantedlineEdit->setText(qry.value(4).toString());
    21. qDebug() << "execute";
    22. }
    23.  
    24. connClose();
    25. }
    26.  
    27. else {
    28. qDebug() << "not execute";
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void FormDialog::on_loadData_clicked()
    2. {
    3. connOpen();
    4. QSqlQueryModel * modal = new QSqlQueryModel();
    5. QSqlQuery* qry = new QSqlQuery(db);
    6. qry->prepare("SELECT FaceID FROM templateinfo");
    7. qry->exec();
    8. modal->setQuery(*qry);
    9.  
    10. ui->comboBox->setModel(modal);
    11.  
    12. qry->next();
    13. qDebug() << (modal->rowCount());
    14.  
    15. }
    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
    Last edited by diyanafadzil; 17th September 2015 at 07:28.

Similar Threads

  1. Replies: 15
    Last Post: 14th September 2015, 13:42
  2. How to get data from mysql ?
    By BuranereLoo in forum Newbie
    Replies: 3
    Last Post: 3rd September 2015, 13:23
  3. Replies: 4
    Last Post: 5th March 2010, 14:20
  4. get mysql table into QComboBox
    By eleanor in forum Qt Programming
    Replies: 17
    Last Post: 10th October 2007, 15:35
  5. Replies: 2
    Last Post: 6th April 2006, 08:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.