×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    34

    Question CPeriodic doesn't run the callback function...

    Dear experienced members,

    I have a code that is compiling well but CPeriodic function is not running the callback function periodically as expected.

    I created a new class TimerC and the CPeriodic object is member of it. I'm instantiating it in the constructor of TimerC. The header is like this:

    class TimerC : public CBase
    {
    public:
    TimerC(CTimer02Container* PointerToWhoStarted);
    ~TimerC();
    static TInt FromCPeriodic(TAny* aObject);
    TInt TimerCMain();
    CPeriodic* iPeriodics;
    CTimer02Container* PointerToWhoStarted;
    }

    and the implementation is:

    TimerC::TimerC(CTimer02Container* container):
    MicroSecTimerUpdate(1000000),PointerToWhoStarted(container)
    {
    iPeriodics=CPeriodic::NewL(10);
    iPeriodics->Start(0,MicroSecTimerUpdate,TCallBack(FromCPeriodic,this));
    }

    TInt TimerC::FromCPeriodic(TAny* aObject)
    {
    RDebug::Print(_L("HELLO HELLO HELLO HELLO FROMCPERIODIC"));
    ((TimerC*)aObject)->TimerCMain();
    }

    TInt TimerC::TimerCMain()
    {
    }

    When I instantiate the CPeriodic in the container then it works fine but not in this case when instantiated in a separate class.

    Do you know why CPeriodic is not working properly from within my newly created class?

    Best regards,

    Carlos.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: CPeriodic doesn't run the callback function...

    Such miracles do not really exist, if your timer works in the container, it is just fine, period.
    What does 'in separate class' mean? If it is a separate, non-GUI project, note that GUI applications run inside an Active Scheduler loop, while non-GUI code has to instantiate and start the scheduler for itself.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    34

    Re: CPeriodic doesn't run the callback function...

    Hello,

    The thing is that I added to the container files (header and source) a new class. The idea is to create and call this class from within the container's ConstructL as :
    .
    .
    .
    InitializeControlsL();
    SetRect( aRect );
    ActivateL();
    TimerC Timer01(this);

    So creating CPeriodic and starting it in the creator of the new class (TimerC) doesn't call the function referenced in TCallBack for some reason. Does it explain my porblem?

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: CPeriodic doesn't run the callback function...

    With "TimerC Timer01(this);" you create a local variable, which is going to be deleted a few lines later, when ConstructL ends.

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    34

    Re: CPeriodic doesn't run the callback function...

    You are right! Thanks a lot. I'm a starter in the art of C++.

Similar Threads

  1. Callback from c function
    By ras123 in forum Qt
    Replies: 7
    Last Post: 2010-07-12, 19:13
  2. Replies: 2
    Last Post: 2008-06-19, 10:19
  3. Callback function not being invoked at all
    By koh888 in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2007-01-31, 12:03
  4. Http callback function
    By srkreddy999 in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2005-10-19, 11:03
  5. callback and leaving function
    By sopta007 in forum Symbian
    Replies: 0
    Last Post: 2003-04-01, 11:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×