Results 1 to 5 of 5

Thread: SQL Server data retrieving speed problem

  1. #1
    Join Date
    Nov 2010
    Posts
    10
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default SQL Server data retrieving speed problem

    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 

  2. #2
    Join Date
    Nov 2010
    Posts
    10
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SQL Server data retrieving speed problem

    It seems like there is no problem with SQL Server data retrieving speed. The QTextTable which I use in QTextEdit to show retrieved data is the one that is slow !!!
    Does anyone know how to make QTextTable works faster?!?

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL Server data retrieving speed problem

    Have you tried to wrap your update code into:
    Qt Code:
    1. ..
    2. texttableTable->setUpdatesEnabled(false);
    3. while (queryAlarms.next())
    4. {
    5. ...
    6. }
    7. texttableTable->setUpdatesEnabled(true);
    To copy to clipboard, switch view to plain text mode 
    HIH

    Joh

  4. The following user says thank you to JohannesMunk for this useful post:

    Aleksandar (4th December 2010)

  5. #4
    Join Date
    Nov 2010
    Posts
    10
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SQL Server data retrieving speed problem

    Thank you Joh,

    This is a valuable note for me, but my app still has speed problem. If you have any more suggestions please share with me!

    Aleksandar

  6. #5
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQL Server data retrieving speed problem

    Hi!

    I don't know if it will help, but you could try the following:

    1) retrieve the number of rows matching your query directly from mysql. => count ?
    2) append this number of rows to your text table at once
    3) fill the data.

    This way the texttable is only resized once. Maybe that increases the speed?

    Joh

  7. The following user says thank you to JohannesMunk for this useful post:

    Aleksandar (24th March 2011)

Similar Threads

  1. Debugger problem retrieving data for watch view hangs
    By frenk_castle in forum Installation and Deployment
    Replies: 0
    Last Post: 6th May 2010, 00:09
  2. Replies: 5
    Last Post: 21st March 2009, 10:10
  3. Replies: 0
    Last Post: 4th December 2008, 06:48
  4. Sql Server cannot retrieve data from select
    By Atomino in forum Qt Programming
    Replies: 10
    Last Post: 7th September 2006, 17:37

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.