Hi, how do I retrieve certain content like name from a table? I want to retrieve all the names and then set them to a label in my form. For now I just want to how to get all the names. So far I've tried using a select count query to first get the number of rows but it didn't work. I'm not sure what functions to use for this if anyone can please help.

Here's what I have done:
Qt Code:
  1. db = QSqlDatabase::addDatabase("QSQLITE");
  2. db.setDatabaseName(Path_to_DB);
  3. QFileInfo checkFile(Path_to_DB);
  4.  
  5. if(checkFile.isFile())
  6. {
  7. if(db.open())
  8. {
  9. qDebug() << "Connected to database file";
  10. }
  11. }else{
  12. qDebug() << "Database file not found";
  13. }
  14.  
  15. QSqlQuery query;
  16. QString qry = QString("SELECT Count(*) FROM customers");
  17.  
  18. query.prepare(qry);
  19.  
  20. if (query.exec())
  21. {
  22. int count = query.result(); //<<<Where I'm stuck
  23. qDebug() << count;
  24. for ( int i = 0; i < count; i++)
  25. {
  26. //create labels for each customer
  27. QLabel *label = new QLabel(QString());
  28. QCheckBox *chkbox = new QCheckBox;
  29.  
  30. Ui::MainWindow *ui;
  31.  
  32. ui->gridLayout->addWidget(label,0,0);
  33. ui->gridLayout->addWidget(chkbox,0,1);
  34.  
  35. }
  36. }
  37. else
  38. {
  39. query.lastError();
  40. }
To copy to clipboard, switch view to plain text mode 

Thanks in advance!