Hello!

I want to show data from my database in QTableWidget. I've wrote somehing like that:

Qt Code:
  1. bool MainWindow::readFromDatabase()
  2. {
  3.  
  4. [...]
  5.  
  6. ok = bdb.open();
  7.  
  8. if (ok)
  9. {
  10. QSqlQuery query("SELECT * FROM mytable", bdb);
  11.  
  12. while (query.next()) {
  13. row = ui->qtable->rowCount();
  14. ui->qtable->insertRow(row);
  15.  
  16. QTableWidgetItem *item1 = new QTableWidgetItem(query.value(0).toString());
  17. ui->qtable->setItem(row, 0, item1);
  18.  
  19. QTableWidgetItem *item2 = new QTableWidgetItem(query.value(1).toString());
  20. ui->qtable->setItem(row, 1, item2);
  21.  
  22. [...]
  23. }
  24.  
  25. query.clear();
  26. } else {
  27. //out << "database open error!" << endl;
  28. }
  29.  
  30. bdb.close();
  31.  
  32. return ok;
  33. }
To copy to clipboard, switch view to plain text mode 

Is it the only way of inserting items into database? Is it necessary to create all these items? Maybe there is way to do it simpler (set position and text which should be there)?

thanks in advance
best regards
Tomasz