Results 1 to 4 of 4

Thread: Advance function doesnt get triggerd on timeout qt timer

  1. #1
    Join Date
    Apr 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Advance function doesnt get triggerd on timeout qt timer

    Dear forum, Im writing a pong game that uses a timer to call advance on the graphicsscene to show the animation on the screen, somehow it doesnt work. I would really appreciate your help. here the code...

    main.CPP :
    QTimer timer;
    QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance()));
    timer.start(1000 / 33);
    return app.exec();

    gameworld.H :

    protected:
    void drawBackground(QPainter *painter, const QRectF &rect);
    virtual void keyPressEvent(QKeyEvent *event);
    virtual void keyReleaseEvent(QKeyEvent *event);
    void advance(int phase);

    GameWorld.CPP :
    void GameWorld::advance(int phase) {
    printf("hello");
    QPointF direction = ball.getDirection();
    if (phase == 0) {
    QRectF rect = sceneRect();
    QPointF point = ball.pos();


    //if (!collidingItems(Qt::IntersectsItemBoundingRect).i sEmpty())
    // ball.setDirection(-direction.x(), direction.y());
    if (point.y() <= rect.top() + 20) {
    ball.setDirection(direction.x(), -direction.y());
    }
    if (point.y() >= rect.bottom() - 20) {
    ball.setDirection(direction.x(), -direction.y());
    }

    if (point.x() <= rect.left() + 20) {
    ball.setDirection(-direction.x(), direction.y());
    }

    if (point.x() >= rect.right() - 20) {
    ball.setDirection(-direction.x(), direction.y());

    }

    } else
    ball.moveBy(direction.x(), direction.y());

    }

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Advance function doesnt get triggerd on timeout qt timer

    advance must be declared as a slot:
    Qt Code:
    1. protected:
    2. void drawBackground(QPainter *painter, const QRectF &rect);
    3. virtual void keyPressEvent(QKeyEvent *event);
    4. virtual void keyReleaseEvent(QKeyEvent *event);
    5.  
    6. protected slots:
    7. void advance();
    To copy to clipboard, switch view to plain text mode 
    edit: and should have no parameters
    If you want to have timeout with parameter, take a look at QTimeLine.

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Advance function doesnt get triggerd on timeout qt timer

    At a first look i noticed two problems:
    1) void advance(int phase); is not declared as a slot
    2) and it has an int parameter (without a default value), so it can't be called without parameters.

    You can read more about signals and slots here.

  4. #4
    Join Date
    Apr 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Advance function doesnt get triggerd on timeout qt timer

    Hey guys thanks for the fast reply,

    with your help I totally figured it out

    really thankfull,

    Greetz

    Niels

Similar Threads

  1. timer problem(timer does not work)
    By masuk in forum Newbie
    Replies: 6
    Last Post: 14th February 2011, 05:00
  2. Waiting for the Timer to emit Siganl timeout()
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 5
    Last Post: 22nd June 2010, 09:18
  3. QProcess timeout
    By MonkeyJLuffy in forum Qt Programming
    Replies: 8
    Last Post: 22nd April 2010, 12:42
  4. Replies: 0
    Last Post: 16th April 2010, 23:21
  5. Tootip Timeout
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2008, 10:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.