Results 1 to 6 of 6

Thread: Waiting for the Timer to emit Siganl timeout()

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Waiting for the Timer to emit Siganl timeout()

    Dear Friends
    I have a QTimer started, now I want wait till the timeout() signal emitted, how can I hang the program for a certain period of time but the timer started should keep emitting its signal. I am not sure how to achieve this , I have been trying something like this.

    MainWindow::startTimer() {
    QTimer * timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(update() ));
    timer->start(60000);
    }
    MainWindow::update()
    {
    if() // if the job is done then
    {
    timer->stop();
    }
    else // wait for the next signal to be emitted after 1 min
    {
    waitcondition.wait(&mutex);
    // Here the problem when its coming here its waiting for an uncertain time its not able to capture the timeout()
    // signal anymore..... How can I achieve this please give me some hint fi anyone knows. Thanks
    }
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Waiting for the Timer to emit Siganl timeout()

    Did you really mean to override QWidget::update()?
    If not you better name MainWindow::update() something else.

    Also, why are you using a wait condition in that situation?
    Usually you don't need threads if you use timers.

    And please use code tags when posting code, its hard to read it this way.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Waiting for the Timer to emit Siganl timeout()

    What is waitcondition ?

  4. #4
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: Waiting for the Timer to emit Siganl timeout()

    waicondition is QWaitCondition. update() is a local slot MainWindow::update() not QWidget......how can stop excutation for sometime or hang the program but I want the timer to keep counting for time and emit timeout() signal ............Please tell me if you're not understing the situation. Thanks for the reply.

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Waiting for the Timer to emit Siganl timeout()

    Show us real code. Maybe You are blocking event loop in "long time job" and timer have no chance to generate signal.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Waiting for the Timer to emit Siganl timeout()

    waicondition is QWaitCondition. update() is a local slot MainWindow::update() not QWidget
    Again:
    using a waint condition in your case, is probably the wrong way to go, and that is causing the problem.
    If MainWindow is derived from QWidget (which it probably does if its a visible object), then you are overriding its update() method,and I don't think you really wanted to do that.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 9th July 2009, 08:59
  2. Waiting WebKit
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 13th May 2009, 03:40
  3. Waiting for multiple threads
    By Bebee in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2008, 17:21
  4. Waiting on a thread?
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2007, 16:13
  5. Waiting for something
    By JonathanForQT4 in forum Newbie
    Replies: 20
    Last Post: 2nd May 2007, 17:35

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.