Why is my timerCallback not called?


#1

I have set up a timer as per the example but it doesn't seem to be getting called. Can anyone help:

 

class MyClass, public Timer{

    public:

        MyClass();

        ~MyClass();

    private:

        void timerCallback() override

        {

            std::cout << "time tick" << std::endl;

        }

}

 

In MyClass.cpp

MyClass:MyClass(){

    startTimer(1000);

}

#2

does this compile?

You want to write 
class MyClass : public Timer

and not 
class MyClass, public Timer


#3

Probably obvious but is that the message loop is properly running?


#4

Sorry, that was a typo (I didn't copy/paste the code). It does compile and is actually:

class MyClass : public Timer

 

@4321 - not exactly sure what you mean?


#5

I have a Timer in a component of the app I am working on and the structure is more like: 

MyClass.h

​
class MyClass: private Timer
{ 
public: 
    MyClass(); 
    ~MyClass(); 

    
    void timerCallback() override; 


private: 
    /* private variables */
}    

MyClass.cpp 

​
MyClass::MyClass()
{ 
    startTimer(1000); 
}

void MyClass::timerCallback()
{

    std::cout << "time tick" << std::endl; 
} 

 

 

 

 


#6

Still nothing! Really weird. Wonder whether it's anything to do with being a console app?


#7

I mean that the Timer class is not the HighResolutionTimer class. IIRC there’s no dedicated thread. So the callbacks are managed by the event loop. If your executable is a GUI JUCEApplication forget my question, but in the contrary (DLL, plug-in, command-line or such) the message loop must be created and started somewhere. There’s various workaround to achieve that, but IMHO you should use the HighResolutionTimer class cited above that is part of the juce_core module.

EDIT : “Wonder whether it’s anything to do with being a console app?” Yes, that’s what i mean :wink:


#8

Ah, ok. So I need to make it a GUI application. Thanks!


#9

... or use the HighResolutionTimer class which will create its own thread to run in. 


#10

Ah, great HighResolutionTimer works straight out the box!