Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Freeze using QTimer with interval 0

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Freeze using QTimer with interval 0

    Hi all,
    I have a class who inherit from QWidget to render a 3D content inside.
    I use a QTimer to refresh the window like that :
    Qt Code:
    1. m_Timer.setInterval( 0 );
    2. connect( &m_Timer, SIGNAL( timeout() ), this, SLOT( repaint() ) );
    3. m_Timer.start();
    To copy to clipboard, switch view to plain text mode 
    When I launch the application and I move the window, the application freeze.
    When I undock a dock window and I try to move it, the application freeze.
    The only one solution I have is to set the interval to 10ms.
    Thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Freeze using QTimer with interval 0

    Use update() instead of repaint(). Besides, what is the point of constantly updating the widget if nothing in it changes? Redraw only when the scene is updated.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2013
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt/Embedded
    Platforms
    Windows

    Default Re: Freeze using QTimer with interval 0

    great coding Freeze using QTime with interval

  4. #4
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Freeze using QTimer with interval 0

    using update() instead of repaint() doesn't change anything, still freeze.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Freeze using QTimer with interval 0

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Freeze using QTimer with interval 0

    Qt Code:
    1. #include <QMainWindow>
    2. #include <QDockWidget>
    3. #include <QApplication>
    4. #include <QTimer>
    5.  
    6. class TestWidget : public QWidget
    7. {
    8. public:
    9.  
    10. TestWidget(QWidget* parent = 0) :
    11. QWidget(parent),
    12. m_Initialized(false)
    13. {
    14. m_Timer.setInterval(0);
    15. }
    16.  
    17. QPaintEngine* paintEngine() const
    18. {
    19. return NULL;
    20. }
    21.  
    22. void showEvent(QShowEvent* event)
    23. {
    24. if(m_Initialized == false)
    25. {
    26. connect(&m_Timer, SIGNAL(timeout()), this, SLOT(repaint()));
    27. m_Timer.start();
    28. m_Initialized = true;
    29. }
    30. }
    31.  
    32. private:
    33.  
    34. QTimer m_Timer;
    35. bool m_Initialized;
    36. };
    37.  
    38. class MainWindow : public QMainWindow
    39. {
    40. public:
    41.  
    42. MainWindow(QWidget* parent = 0) :
    43. QMainWindow(parent)
    44. {
    45. QDockWidget* NewDock = new QDockWidget("Test", this);
    46. NewDock->setWidget(new TestWidget(this));
    47. addDockWidget(Qt::BottomDockWidgetArea, NewDock);
    48. }
    49. };
    50.  
    51. int main(int argc, char *argv[])
    52. {
    53. QApplication a(argc, argv);
    54. MainWindow w;
    55. w.show();
    56. return a.exec();
    57. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Alundra; 28th May 2013 at 00:44.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Freeze using QTimer with interval 0

    What is returning an empty paint engine meant to do in this example? What exactly would you expect to receive in the widget?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Freeze using QTimer with interval 0

    Doesn't freeze here, not that it actually does anything useful. It does, however, tie up a CPU core at near 100% utilisation... but then that is what you are asking it to do with a zero timer.

  9. #9
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Freeze using QTimer with interval 0

    The real widget in the application initialize a render window from a 3D Engine.
    The return NULL is to remove the flickering.
    To reproduce the freeze you have to undock and move the dock or the application window.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Freeze using QTimer with interval 0

    No freeze here... sorry...

    Did you check that the small code snippet that you posted actually freezes?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Freeze using QTimer with interval 0

    I have retested again and the freeze is real and not on this computer only.
    Only try to move the window and the freeze will be there.
    I have to ctrl+alt+enter to end the application.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Freeze using QTimer with interval 0

    Which platform did you test it on? Which Qt version?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Freeze using QTimer with interval 0

    I use QT 5.0.2.
    On my laptop using windows 8 I don't have the freeze, but on windows 7 I have the freeze.

  14. #14
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Freeze using QTimer with interval 0

    Do you have a workaround to update the widget without a timer and who works for all platform ?

  15. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Freeze using QTimer with interval 0

    As Wysota said, when the data that is driving whatever you display in the widget changes, call update() and make sure you program does not block the Qt event loop. It really is that simple and it's not a "workaround". If the data changes every millisecond then you might need to be a bit smarter about how often you update() the widget.

    You have not shown us anything that might drive the widget content so I don't see how we can be specific.


    BTW: I just built your code with Qt 5.0.1 on Windows 7 32-bit. No hanging, lockups etc. It does sit, as expected, on near 100% CPU.

  16. #16

    Default Re: Freeze using QTimer with interval 0

    Hi,
    I have the same issue. The sample code provided in this thread clearly displays my use case (do not care about the 100% CPU load, it should just trigger rendering frames as fast as possible!).

    The problem was introduced in my case with Qt 4.8.2. I run my software under Windows compiled as x64 code and I found the following cases:

    Windows 7 Aero enabled -> freeze on window move
    Windows 7 classic desktop -> no problem
    Windows 8 (DWM enabled by default) -> no problem

    I tried different ways to refresh the widget such as calling update() at the end of paintEvent() to schedule another frame, but the behavior at the end remains the same. This seems to be a bug in Qt. There is NO way to continuously refresh a rendering widget anymore.

    Does anyone else noticed this behavior introduced sometime around Qt 4.8.x and does there exist a workaround?

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Freeze using QTimer with interval 0

    The problem is with Windows event handling. When you move a window around by dragging, events are not delivered to this window.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #18

    Default Re: Freeze using QTimer with interval 0

    Hi,
    thanks for the answer, but how does this affect the Aero/non-Aero case and how can it be solved. It worked before and still is a default case as proposed by Qt itself.

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Freeze using QTimer with interval 0

    Quote Originally Posted by Chris Lux View Post
    thanks for the answer, but how does this affect the Aero/non-Aero case and how can it be solved.
    Aero is Windows desktop compositor. It is (probably) the component responsible for the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #20

    Default Re: Freeze using QTimer with interval 0

    this does not explain why it was working prior to Qt 4.8.x with the same Windows installation and drivers.

Similar Threads

  1. How to change the Interval Type in QwtPlot?
    By ObiWanKenobe in forum Qwt
    Replies: 4
    Last Post: 16th April 2013, 12:58
  2. Replies: 15
    Last Post: 4th August 2012, 20:11
  3. Replies: 1
    Last Post: 16th May 2012, 12:40
  4. Phonon and the meta interval
    By huilui in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2012, 07:08
  5. QSpinBox interval
    By Jordan in forum Newbie
    Replies: 9
    Last Post: 25th May 2010, 12:07

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.