Results 1 to 20 of 23

Thread: Freeze using QTimer with interval 0

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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; 27th May 2013 at 23:44.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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.


Similar Threads

  1. How to change the Interval Type in QwtPlot?
    By ObiWanKenobe in forum Qwt
    Replies: 4
    Last Post: 16th April 2013, 11:58
  2. Replies: 15
    Last Post: 4th August 2012, 19:11
  3. Replies: 1
    Last Post: 16th May 2012, 11:40
  4. Phonon and the meta interval
    By huilui in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2012, 06:08
  5. QSpinBox interval
    By Jordan in forum Newbie
    Replies: 9
    Last Post: 25th May 2010, 11: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
  •  
Qt is a trademark of The Qt Company.