[Solved] function finish only after stopping two timers



  • Hello friends,

    I have a function & 2 timers. I start 2 timers inside the function.
    I need the function finish only after stopping 2 timers.

    for example
    @
    int foo()
    {
    ... sth ...

    timer1.start();

    timer2.strart();

    WaitForStoppingTwoTimers();

    return 1;
    }
    @

    Thanks a lot.
    Ya Ali.



  • One of the ways of doing it.

    @Widget {
    private :
    QTimer *tim1;
    QTimer *tim2;
    QEventLoop eLoop;
    };

    void Widget::foo(){
    tim1 = new QTimer;
    tim2 = new QTimer;
    tim1->setInterval(5000);
    tim2->setInterval(10000);
    tim2->start();
    tim1->start();
    connect(tim1,SIGNAL(timeout()),this,SLOT(time1foo()));
    connect(tim2,SIGNAL(timeout()),this,SLOT(time2foo()));
    qDebug() << "Wait here till Timer expired"<<endl;
    this->eLoop.exec();
    qDebug() << "I am here" <<endl;
    }

    void Widget::time1foo(){
    qDebug() << "First Timer expired " <<endl;
    //eLoop.exit();
    tim1->stop();
    }

    void Widget::time2foo(){
    qDebug() << "SecondTimer Timer expired " <<endl;
    eLoop.exit();
    tim2->stop();
    }@



  • Hello dear Dheerendra,
    Thank you very very much :)
    worked!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.