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. Emit a signal fixed number of time with QTimer
Forum Updated to NodeBB v4.3 + New Features

Emit a signal fixed number of time with QTimer

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.7k Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Anurag2904
    wrote on last edited by
    #1

    Hi All,

    I am working on a project where i draw an ellipse on Graphics View (using scene). I am using QTimer to emit a signal which triggers the SLOT fuction which draws on Graphics View. After drawing for 9 such times, I want to stop and now draw any more. Is there a way to make QTimer not trigger after 9 signals?

    I am using signals to draw on Graphics View, because after each draw I want new ellipse to show immediately. Is there any other solution ?

    Thanks,
    Anurag

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Yes: count the number of occurrences it fired and stop the timer after that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • yuvaramY Offline
        yuvaramY Offline
        yuvaram
        wrote on last edited by yuvaram
        #3

        Hi @Anurag2904

        This would help u.

        #include "sample1.h"

        sample1::sample1(QObject *parent) : QObject(parent)
        {
        count = 0;
        mtimer.setInterval(1000);
        connect(&mtimer,SIGNAL(timeout()),this,SLOT(sLotTimer()));
        mtimer.start();
        }

        void sample1::sLotTimer()
        {

        count ++;
        //business logic
        qDebug()<<Q_FUNC_INFO<<endl;
        if(count <= 9){
            mtimer.start();
        }else{
            mtimer.stop();
        }
        

        }

        Yuvaram Aligeti
        Embedded Qt Developer
        : )

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Anurag2904
          wrote on last edited by
          #4

          Thanks a lot guys. Issue solved by issuing stop() when counter hits 9

          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