Results 1 to 6 of 6

Thread: Slow Graphics since Qt 5.6.0

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Feb 2015
    Posts
    14
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Slow Graphics since Qt 5.6.0

    Hi wysota,

    I found the bug. It's in QPainter:drawText() but only in combination with QPainter::setFont(). The following code runs two tests. A Windows 10 desktop application build with Qt 5.4.2, Qt 5.5.0 and Qt 5.5.1 will execute both tests with the same speed in debug mode. But build with Qt 5.6.0, Qt 5.6.1 or Qt 5.7.0 Test2 takes about 9 times longer than Test1!

    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QPainter>
    4. #include <QElapsedTimer>
    5.  
    6. class Widget : public QWidget
    7. {
    8. public:
    9. Widget();
    10.  
    11. protected:
    12. void timerEvent(QTimerEvent*);
    13. void paintEvent(QPaintEvent*);
    14.  
    15. private:
    16. QElapsedTimer elapsedTimer;
    17. int timerId;
    18. int elapsedTime1, elapsedTime2;
    19. bool isFinished1, isFinished2, isFinished3;
    20. int i, x1, x2, y1, y2;
    21. };
    22.  
    23. Widget::Widget()
    24. {
    25. setAutoFillBackground(true);
    26. setPalette(Qt::white);
    27.  
    28. timerId = startTimer(1);
    29. elapsedTimer.start();
    30.  
    31. i=0; x1=0; x2=0;
    32. isFinished1 = isFinished2 = isFinished3 = false;
    33. }
    34.  
    35. void Widget::timerEvent(QTimerEvent*)
    36. {
    37. update();
    38. }
    39.  
    40. void Widget::paintEvent(QPaintEvent*)
    41. {
    42. QPainter painter(this);
    43.  
    44. if (i > 0 && i < 800)
    45. {
    46. // 'Test1' runs about 9 times faster than 'Test2' on Qt 5.6.0, Qt 5.6.1 and Qt 5.7.0
    47.  
    48. y1 = 10;
    49. painter.setFont(QFont("Arial", 14));
    50. painter.drawText(x1, y1 += 30, "Test 1");
    51. painter.drawText(x1, y1 += 30, "row 01");
    52. painter.drawText(x1, y1 += 30, "row 02");
    53. painter.drawText(x1, y1 += 30, "row 03");
    54. painter.drawText(x1, y1 += 30, "row 04");
    55. painter.drawText(x1, y1 += 30, "row 05");
    56. painter.drawText(x1, y1 += 30, "row 06");
    57. painter.drawText(x1, y1 += 30, "row 07");
    58. painter.drawText(x1, y1 += 30, "row 08");
    59. painter.drawText(x1, y1 += 30, "row 09");
    60. painter.drawText(x1, y1 += 30, "row 10");
    61. painter.drawText(x1, y1 += 30, "row 11");
    62. painter.drawText(x1, y1 += 30, "row 12");
    63. x1++;
    64.  
    65. elapsedTime1 = elapsedTimer.elapsed();
    66. }
    67. else if (i > 800 && i < 1600)
    68. {
    69. // 'Test2' takes about 9 times longer than 'Test1' on Qt 5.6.0, Qt 5.6.1 and Qt 5.7.0
    70.  
    71. isFinished1 = true;
    72.  
    73. y2 = 300;
    74. painter.setFont(QFont("Arial", 14));
    75. painter.drawText(x2, y2 += 30, "Test 2");
    76. painter.setFont(QFont("Caladea", 14));
    77. painter.drawText(x2, y2 += 30, "row 01");
    78. painter.setFont(QFont("Tomaha", 14));
    79. painter.drawText(x2, y2 += 30, "row 02");
    80. painter.setFont(QFont("Consolas", 14));
    81. painter.drawText(x2, y2 += 30, "row 03");
    82. painter.setFont(QFont("Calibri", 14));
    83. painter.drawText(x2, y2 += 30, "row 04");
    84. painter.setFont(QFont("Impact", 14));
    85. painter.drawText(x2, y2 += 30, "row 05");
    86. painter.setFont(QFont("Courier New", 14));
    87. painter.drawText(x2, y2 += 30, "row 06");
    88. painter.setFont(QFont("Gorgia", 14));
    89. painter.drawText(x2, y2 += 30, "row 07");
    90. painter.setFont(QFont("Verdana", 14));
    91. painter.drawText(x2, y2 += 30, "row 08");
    92. painter.setFont(QFont("Times New Roman", 14));
    93. painter.drawText(x2, y2 += 30, "row 09");
    94. painter.setFont(QFont("Microsoft Sans Serif", 14));
    95. painter.drawText(x2, y2 += 30, "row 10");
    96. painter.setFont(QFont("Segoe UI", 14));
    97. painter.drawText(x2, y2 += 30, "row 11");
    98. painter.setFont(QFont("Trebuchet MS", 14));
    99. painter.drawText(x2, y2 += 30, "row 12");
    100. x2++;
    101.  
    102. elapsedTime2 = elapsedTimer.elapsed();
    103. }
    104. else if (i > 1600)
    105. {
    106. isFinished2 = true;
    107. }
    108. i++;
    109.  
    110. if (isFinished1)
    111. {
    112. painter.setFont(QFont("Arial", 12, QFont::Bold));
    113. painter.drawText(QPoint(200, 150), "'Test1' elapsed time in seconds: " + QString::number(elapsedTime1/1000.0));
    114. }
    115. if (isFinished2)
    116. {
    117. painter.drawText(QPoint(200, 430), "'Test2' elapsed time in seconds: " + QString::number((elapsedTime2-elapsedTime1)/1000.0));
    118. isFinished3 = true;
    119. }
    120. if (isFinished3)
    121. {
    122. painter.setFont(QFont("Arial", 11));
    123. painter.drawText(QPoint(200, 620), "On Windows Desktop with Qt 5.4.2, Qt 5.5.0 and Qt 5.5.1 Test1 and Test2 are both equally fast.");
    124. painter.drawText(QPoint(200, 650), "On Windows Desktop with Qt 5.6.0, Qt 5.6.1 and Qt 5.7.0 Test2 is approx 9 times slower than Test1 !");
    125. painter.drawText(QPoint(200, 680), "No matter if compiled with MinGW 32bit or MSVC 32 or 64bit");
    126. killTimer(timerId);
    127. }
    128. }
    129.  
    130. int main(int argc, char *argv[])
    131. {
    132. QApplication app(argc, argv);
    133. Widget widget;
    134. widget.showMaximized();
    135. return app.exec();
    136. }
    To copy to clipboard, switch view to plain text mode 
    Did you know how to report a bug report to the Qt developer team? Never did that before. Can you help me with this?
    Last edited by mireiner; 17th June 2016 at 12:17.

Similar Threads

  1. graphics
    By nabeel in forum Qt Programming
    Replies: 0
    Last Post: 5th September 2013, 13:08
  2. Qt-Graphics
    By grsandeep85 in forum Qt Programming
    Replies: 3
    Last Post: 30th October 2009, 09:33
  3. Qt Graphics
    By soumya in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2009, 09:41
  4. 3D graphics
    By impeteperry in forum Qt Programming
    Replies: 3
    Last Post: 19th July 2009, 08:00
  5. graphics view slow
    By dognzhe in forum Qt Programming
    Replies: 16
    Last Post: 11th May 2009, 17:36

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
  •  
Qt is a trademark of The Qt Company.