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. How can I connect a signal to Qtimer slot start()
Forum Updated to NodeBB v4.3 + New Features

How can I connect a signal to Qtimer slot start()

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.1k 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.
  • D Offline
    D Offline
    dziko147
    wrote on last edited by
    #1

    Hello ,
    I want to start the QTimer in a specific condition .
    So I think about send a signal to start() slot .
    But I couldn't do it .

    Who can suggest a way ?
    thank you

    KroMignonK 1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qt embedded developer
      wrote on last edited by
      #2

      you can use signal and slot . so where you condition become true there you have to emit signal. and in constructor you can call start timer slot .

      1 Reply Last reply
      0
      • D dziko147

        Hello ,
        I want to start the QTimer in a specific condition .
        So I think about send a signal to start() slot .
        But I couldn't do it .

        Who can suggest a way ?
        thank you

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @dziko147 said in How can I connect a signal to Qtimer slot start():

        Hello ,
        I want to start the QTimer in a specific condition .
        So I think about send a signal to start() slot .
        But I couldn't do it .
        Who can suggest a way ?
        thank you

        Can you show what you have tried? So it is easier for us to explain what going wrong.

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        1
        • D Offline
          D Offline
          dziko147
          wrote on last edited by
          #4

          @KroMignon

          connect(&m_fetchFrameTimer, & QTimer::timeout, this, &Backend::statuspican);
          
          connect(this,SIGNAL(signalgetdataclicked()),this,SLOT(m_fetchFrameTimer.start(2000))); //I thinked about something like this 
          
          
          KroMignonK J.HilkJ 2 Replies Last reply
          0
          • D dziko147

            @KroMignon

            connect(&m_fetchFrameTimer, & QTimer::timeout, this, &Backend::statuspican);
            
            connect(this,SIGNAL(signalgetdataclicked()),this,SLOT(m_fetchFrameTimer.start(2000))); //I thinked about something like this 
            
            
            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #5

            @dziko147 said in How can I connect a signal to Qtimer slot start():

            connect(this,SIGNAL(signalgetdataclicked()),this,SLOT(m_fetchFrameTimer.start(2000))); //I thinked about something like this

            This do no made sense.

            you can connect a "sender" signal to a "receiver" slot (or signal).
            SIGNAL() is used to define the signal to connect (function name and parameter types, not variable names)
            SLOT() is used to define the slot to connect (function name and parameter types, not variable names)

            What you are trying to do is not allowed.

            You could use a lambda function, like this (I suppose the class name is Backend):

            connect(this, &Backend::signalgetdataclicked,this, [this](){
                m_fetchFrameTimer.start(2000); 
            }); 
            

            Please, take 1 or 2 minutes to learn how connect() works. It is very well documented here: https://doc.qt.io/qt-5/signalsandslots.html

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            2
            • D dziko147

              @KroMignon

              connect(&m_fetchFrameTimer, & QTimer::timeout, this, &Backend::statuspican);
              
              connect(this,SIGNAL(signalgetdataclicked()),this,SLOT(m_fetchFrameTimer.start(2000))); //I thinked about something like this 
              
              
              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by J.Hilk
              #6

              @dziko147

              connect(this,SIGNAL(signalgetdataclicked()),this,SLOT(m_fetchFrameTimer.start(2000)));

              since you're probably trying to start the timer with different times, I would suggest a custom signal for this:

              signals:
              ....
              void startFetchFrameTimer(int interval);
              

              and use that in a "regular" connect,

              Old syntax:

              connect(this, SIGNAL(startFetchFrameTimer(int)), &m_fetchFrameTimer, SLOT(start(int)));
              

              new Syntax

              connect( this, &Backend:: startFetchFrameTimer, &m_fetchFrameTimer, qOverload<int>::of(&QTimer::start));
              

              then you just emit the signal wherever you want, and you're fine to go:

              emit startFetchFrameTimer(1000);
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              3

              • Login

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