Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] function finish only after stopping two timers

[Solved] function finish only after stopping two timers

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 662 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MohammadReza
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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();
      }@

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MohammadReza
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved