Results 1 to 2 of 2

Thread: problem with making the application sleep for a sec

  1. #1
    Join Date
    Apr 2010
    Location
    Katowice, Poland
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default problem with making the application sleep for a sec

    Hi! I'm trying to write the application that will:
    1) in the beginning draw an ellipse in the centre of a widget
    2) then draw the second ellipse and make it move
    Of course this is only the part of something bigger (there will be much more ellipses), but now I have the problem to make this second ellipse move. I'm trying to remember the coordinates of the ellipse in the list and change them in the loop. And after each change of the coordinates I want the application to sleep and repaint the widget. I want to make it sleep because it's the one of the ways to make the move of the ellipse visible. I tried various methods, but unfortunately, nothing worked. I launch the application, and no move is visible - I can see only the last position of the ellipse. Could anyone help me? Thanks in advance! There is the part of my code:

    Qt Code:
    1. void RightWindow::paintEvent(QPaintEvent* event) {
    2. QPainter painter(this);
    3. painter.setBrush(Qt::SolidPattern);
    4. for(int i = 0; i < pointsList.size(); i++) {
    5. painter.drawEllipse(QRect(pointsList.at(i), *(getRadius())));
    6. }
    7. }
    8.  
    9. void RightWindow::start(double x, double y) {
    10. setNewX(x);
    11. setNewY(y);
    12. pointsList.append(QPoint(getNewX(), getNewY()));
    13. repaint();
    14. setNewX(x - 10);
    15. setNewY(y - 10);
    16. pointsList.append(QPoint(getNewX(), getNewY()));
    17. repaint();
    18. for(int i = 0; i < 10; i++) {
    19. QPoint point = pointsList.at(pointsList.size() - 1);
    20. point.setX(point.x() + 2);
    21. pointsList.removeAt(pointsList.size() - 1);
    22. pointsList.append(point);
    23. QTimer::singleShot(1000, this, SLOT(repaint()));
    24. repaint();
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    RightWindow class is my class that inherits after QWidget. And the methods such as getNewX() are my own method written by me...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: problem with making the application sleep for a sec

    See QTimer (edit: ups, you already use it), QTimeLine or QPropertyAnimation.

    Edit: also use update instead of repaint.
    Edit2: your loop is nonesense. call the calculating function with a timer, not the update function:
    Qt Code:
    1. void XXX::calc() {
    2. //calculate new values
    3. update();
    4. // single shot to this function.
    5. }
    To copy to clipboard, switch view to plain text mode 
    (a single shot is not the best solution!)
    Last edited by Lykurg; 2nd May 2010 at 08:57. Reason: updated contents

Similar Threads

  1. Making my Application sole focus !
    By fassage in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2009, 10:13
  2. Making Application Plugin-Aware
    By assismvla in forum Qt Programming
    Replies: 3
    Last Post: 23rd April 2009, 13:35
  3. Replies: 1
    Last Post: 14th June 2007, 15:52
  4. Making some simple help for my application
    By Godlike in forum Newbie
    Replies: 9
    Last Post: 21st April 2006, 18:43
  5. sleep - sleeps, but not when I want it to sleep
    By nongentesimus in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 14:43

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.