Hi guys,
I 'm building Qt application based on QTextEdit. The app retrieves data from SQL Server database and inserts it into QTextEdit in the form of table. (Later I create pdf or print)
Everything works fine except for the speed.

Problem:
Data retrieving lasts too long. It seems to me that each time I get record from the QSqlQuery object, the app sends query to SQL Server. Shouldn't QSqlQuery object have buffer with returned data set?

Potential solution:
QSqlTableModel + QTableView works much faster, but I really need that data in the QTextEdit object for inserting some other data and printing!

Does anyone know faster way for this?

Example code:
Qt Code:
  1. …
  2. //CREATE & EXECUTE QUERY
  3. QSqlQuery queryAlarms;
  4. queryAlarms.exec(“SELECT …”);
  5. //FULFIL TEXT TABLE WITH RECORDS
  6. FulfilTableWithRecords (queryAlarms, cursor, texttableTable, formatCellFormat2);
  7. …
  8.  
  9. void AlarmsEditor::FulfilTableWithRecords (QSqlQuery queryAlarms, QTextCursor cursor, QTextTable* texttableTable, QTextCharFormat formatCellFormat2)
  10. {
  11. QSqlRecord record;
  12. QString strAlarmTime;
  13. QString strAckTime;
  14. QString strReturnTime;
  15. QString strTagName;
  16. double doubleValue;
  17. QString strLimit;
  18. QString strKomentar1;
  19. QString strAckOperatorName;
  20. QString strKomentar2;
  21.  
  22. while(queryAlarms.next())
  23. {
  24. //INSERT ROW IN THE TABLE
  25. texttableTable->appendRows(1);
  26. //GET ONE RECORD
  27. record = queryAlarms.record();
  28. //GET FIELDS FROM THE RECORD
  29. strAlarmTime = record.value(0).toString();
  30. strAckTime = record.value(1).toString();
  31. strReturnTime = record.value(2).toString();
  32. strTagName = record.value(3).toString();
  33. doubleValue = record.value(4).toDouble();
  34. strLimit = record.value(5).toString();
  35. strKomentar1 = record.value(6).toString();
  36. strAckOperatorName = record.value(7).toString();
  37. strKomentar2 = record.value(8).toString();
  38. //CHANGE TIME FORMAT. "2010-07-27T07:27:27" to "2010-07-27 07:27:27"
  39. strAlarmTime.replace("T", " ");
  40. strAckTime.replace("T", " ");
  41. strReturnTime.replace("T", " ");
  42. //FULFIL ONE ROW IN THE TABLE
  43. cursor.insertText(strAlarmTime, formatCellFormat2);
  44. cursor.movePosition(QTextCursor::NextCell);
  45. cursor.insertText(strAckTime, formatCellFormat2);
  46. cursor.movePosition(QTextCursor::NextCell);
  47. cursor.insertText(strReturnTime, formatCellFormat2);
  48. cursor.movePosition(QTextCursor::NextCell);
  49. cursor.insertText(strTagName, formatCellFormat2);
  50. cursor.movePosition(QTextCursor::NextCell);
  51. cursor.insertText(tr("%1").arg(doubleValue), formatCellFormat2);
  52. cursor.movePosition(QTextCursor::NextCell);
  53. cursor.insertText(strLimit, formatCellFormat2);
  54. cursor.movePosition(QTextCursor::NextCell);
  55. cursor.insertText(strKomentar1, formatCellFormat2);
  56. cursor.movePosition(QTextCursor::NextCell);
  57. cursor.insertText(strAckOperatorName, formatCellFormat2);
  58. cursor.movePosition(QTextCursor::NextCell);
  59. cursor.insertText(strKomentar2, formatCellFormat2);
  60. cursor.movePosition(QTextCursor::NextRow);
  61. }
  62. }
To copy to clipboard, switch view to plain text mode