Results 1 to 6 of 6

Thread: Qtimer problem

  1. #1

    Default Qtimer problem

    i am using qtimer for traffic light change in junction. i have created four state and each state run for some second.
    But after sometime it hang and when i see task manager the memory consumed by that application rises.
    i have created four state n each state is called from previous state.please tell me where i am wrong..







    timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(state1() ))

    void Dialog::state1()
    {
    timer->stop();

    //code to draw appropriate traffic light

    connect(timer,SIGNAL(timeout()),this,SLOT(state2() ));
    timer->start(2000);
    }

    void Dialog::state2()
    {
    timer->stop();

    //code to draw traffic light

    connect(timer,SIGNAL(timeout()),this,SLOT(state3() ));
    timer->start(2000);
    }

    void Dialog::state3()
    {
    timer->stop();

    //code to draw appropriate traffic light

    connect(timer,SIGNAL(timeout()),this,SLOT(state4() ));
    timer->start(2000);
    }
    void Dialog::state4()
    {
    timer->stop();

    //code to draw appropriate traffic light

    connect(timer,SIGNAL(timeout()),this,SLOT(state1() ));
    timer->start(2000);
    }

  2. #2
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Thanks
    8
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qtimer problem

    try use disconnect(timer,SIGNAL(timeout()),this,SLOT(state 1()) before calling connect(timer,SIGNAL(timeout()),this,SLOT(state2() )); same process for all ...
    i think it will help for you ...

  3. #3
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qtimer problem

    use connect only once ... every time u call the state() function u r establishing a new connection .. and all the connect will run concurrently .. or disconnect like Mr.pradeep said
    "Behind every great fortune lies a crime" - Balzac

  4. #4
    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: Qtimer problem

    Do not use the connect / disconnect, use QTimer::singleShot like this :
    Qt Code:
    1. QTimer::singleShot(2000,this,SLOT(state1() ));
    2.  
    3. void Dialog::state1()
    4. {
    5. //code to draw appropriate traffic light
    6. QTimer::singleShot(2000,this,SLOT(state2() ));
    7. }
    To copy to clipboard, switch view to plain text mode 
    and so on.

  5. #5

    Default Re: Qtimer problem

    Thanks. It really help me.
    I also have another problem. i am using open cv to play video.i am displaying video using Qlabel.
    The open cv use infinite loop to play the video. But i want to implement above traffic light in parallel . i want to show the
    video of four side of the junction and using image processing i want to control the traffic light.
    plz help.

  6. #6
    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: Qtimer problem

    Please tell us what the problem is, why you think it is a problem, and what you have read/done to try to sort it out.

Similar Threads

  1. Replies: 15
    Last Post: 4th August 2012, 19:11
  2. Little Qtimer problem
    By gen_mass in forum Newbie
    Replies: 1
    Last Post: 24th July 2010, 02:19
  3. problem in qtimer
    By mohanakrishnan in forum Qt Programming
    Replies: 4
    Last Post: 26th November 2009, 11:55
  4. Problem with QTimer under Win XP
    By wzielj in forum Qt Programming
    Replies: 9
    Last Post: 26th January 2009, 14:04
  5. Problem about QTimer
    By pawer in forum Qt Programming
    Replies: 5
    Last Post: 22nd January 2008, 13:02

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.