CPeriodic Error

Login to reply to this topic.
Wed, 2005-03-30 20:53
Joined: 2005-03-20
Forum posts: 24
I Know that there's a lot of post about this argument.

I've tried all the solution also using the API guide with the exalmples but always the compiler give me the same error.

My code is:

Code:
void CNsTorchContainer::StartTimer()  {
   const TInt tickInterval=1000000;
   iPeriodic=CPeriodic::NewL(0); // neutral priority
   iPeriodic->Start(tickInterval,tickInterval,TCallBack(Tick, this));
   }


void CNsTorchContainer::StopTimer()
  {
  iPeriodic->Cancel();
  delete iPeriodic;
  iPeriodic = NULL;
  }

TInt CNsTorchContainer::Tick(TAny* aObject)
  {
  // call non-static method
  ((CNsTorchContainer*)aObject)->BackLight();
  // Allow the timer to continue itÕs work
  return 0;
  }

void CNsTorchContainer::BackLight()
  {

  }


It seems to be all ok with the other solutions but compiling it gives me this error:

"NsTorchcontainer.cpp":     C2665: "TCallBack::TCallBack": noone of 4 overload can convert the parameter 1 from type "TInt (TAny *)" at line 118


The Line 118 is this one

[code]
    iPeriodic->Start(tickInterval,tickInterval,TCallBack(Tick, this));
[/code]

So... my compiler is abusing drugs? Cheezy

Wed, 2005-03-30 21:11
Joined: 2005-03-04
Forum posts: 33
CPeriodic Error
i think you should buy a book and learn c or c++ first than try to program something.
the method want a void pointer and you give him a integer reference.
try to cast to tany*, e.g.
(TAny*) &tickValue
Wed, 2005-03-30 21:16
Joined: 2005-03-20
Forum posts: 24
CPeriodic Error
ok but the probelm is that this example is inside the Api reference... Smiley


this is the example present in the .chm file of the dsk.

Code:
void CMyGameView::StartTimerL()

{

  // tickInterval in microseconds; 100000 equals to 1/10 seconds
  const TInt KTickInterval = 100000;

  iPeriodic = CPeriodic::NewL(CActive::EPriorityLow);

  iPeriodic->Start(KTickInterval,        

     KTickInterval,TCallBack(Tick, this));

}



// Stops the timer

void CMyGameView::StopTimer()

  {

  iPeriodic->Cancel();

  delete iPeriodic;

  iPeriodic = NULL;

  }



// Called by the timer when given interval elapsed

// This must be static method

TInt CMyGameView::Tick(TAny* aObject)

  {
  // call non-static method

  ((CMyGameEngine*)aObject)->NextTick();

  // Allow the timer to continue itÕs work
  return 1;
  }
Wed, 2005-03-30 22:20
Joined: 2004-09-14
Forum posts: 140
CPeriodic Error
Could you post your header file for CNsTorchContainer, my guess is the Tick function may not be marked as static?

Paul Todd

Wed, 2005-03-30 22:48
Joined: 2005-03-20
Forum posts: 24
CPeriodic Error
infact... it wasn't marked static. Solved before your post.

Anyway... tnx a lot Paul

Sorry for the disturb.
Thu, 2005-03-31 08:19
Joined: 2004-07-28
Forum posts: 1379
CPeriodic Error
Quote from: dembi00
i think you should buy a book and learn c or c++ first than try to program something.
the method want a void pointer and you give him a integer reference.
try to cast to tany*, e.g.
(TAny*) &tickValue

I think posts like this are ironic Smiley

didster

Thu, 2005-03-31 08:44
Joined: 2005-03-20
Forum posts: 24
CPeriodic Error
Today I've copied the src to the notebook and tried to compile it....

the code is the same of the other pc....same sdk...same compiler

Code:
if ( iPeriodic->IsActive() )
       {
     StopTimer();
       }
  }
else {
 if ( !iPeriodic->IsActive() )
               {
           StartTimer();
               }


 }

}

void CNsTorchContainer::StartTimer()  {
   const TInt tickInterval=1000000;

  // iPeriodic->Start(tickInterval,tickInterval,TCallBack(CNsTorchContainer::Tick, this));
   iPeriodic->Start(tickInterval,tickInterval,TCallBack(Tick, this));
   }


void CNsTorchContainer::StopTimer()
  {
  iPeriodic->Cancel();
  delete iPeriodic;
  iPeriodic = NULL;
  }

TInt CNsTorchContainer::Tick(TAny* aObject)
  {
  // call non-static method
// ( static_cast<CNsTorchContainer*>( aObject ) )->BackLight();
  ((CNsTorchContainer*)aObject)->BackLight();
  // Allow the timer to continue itÕs work
  return 0;
  }

void CNsTorchContainer::BackLight()
  {
User::ResetInactivityTime();
  }

These are the errors:

"NsTorchcontainer.cpp":     C2662: "CNsTorchContainer::StopTimer": impossibile convertire il puntatore "this" da "const CNsTorchContainer" a "CNsTorchContainer &" at line 101
"NsTorchcontainer.cpp":     C2662: "CNsTorchContainer::StartTimer": impossibile convertire il puntatore "this" da "const CNsTorchContainer" a "CNsTorchContainer &" at line 107

The lines of the errores are where i call the function to start and stop the timer

 {
     StopTimer();

and

 {
     StartTimer();


I dunno the reasons... what's changed ?
Thu, 2005-03-31 08:52
Joined: 2005-03-20
Forum posts: 24
CPeriodic Error
At the beginning the function where i start the timer was

Code:
void CNsTorchContainer::UpdateDisplay(const TRect& aRect) const

Now to solve the problem i had to modify it to

Code:
void CNsTorchContainer::UpdateDisplay(const TRect& aRect)

So my question is... why with this notebook i have to change the source code?
Thu, 2005-03-31 08:52
Joined: 2004-07-28
Forum posts: 1379
CPeriodic Error
Are the metods you are calling Start/StopTimer from const?

It's odd it's not working now - are you 100% sure everything is the same?  Something must be different somewhere - try a full clean and rebuild on both.

didster

Thu, 2005-03-31 08:55
Joined: 2004-07-28
Forum posts: 1379
CPeriodic Error
Quote from: spideronz
So my question is... why with this notebook i have to change the source code?

Well, the notebook is correct - Start and Stop timer are not const, therefor shouldn't be allowed to be called from a const method.

Usually, things like this happen when the compiler (on the non-notebook) gets its head in a mess over what does and doesn't need rebuilding.  Try an abld reallyclean followrd by a complete rebuild on the PC, you should see the error then.

didster

Thu, 2005-03-31 09:06
Joined: 2005-03-20
Forum posts: 24
CPeriodic Error
strange.... at home i've cleaned it and rebuilded it a lot of time without error.

Tnx for the answer. Very polite Smiley
Thu, 2005-03-31 09:49
Joined: 2005-03-20
Forum posts: 24
CPeriodic Error
Can I ask another thing?

Using Draw function e UpdateDisplay without [const] the src compiles but the program doesn't run in the emulator o in the mobile.

The fullscreen mode is not activated and the bitmap are not generated.

Probably there's  a logic explanation... but searching around i find anything...
Thu, 2005-03-31 09:56
Joined: 2004-07-28
Forum posts: 1379
CPeriodic Error
Who calls UpdateDisplay?  Could you put up that code?

Have you put a break point in UpdateDisplay?  Does it even get called?

didster

Thu, 2005-03-31 10:11
Joined: 2005-03-20
Forum posts: 24
CPeriodic Error
This is the code

Code:
void CprovaContainer::Draw(const TRect& aRect)
{
UpdateDisplay(aRect);

}


void CprovaContainer::UpdateDisplay(const TRect& aRect) {

 CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(iBackgroundColor);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);


if (this->status != 5) {
 if ( iPeriodic->IsActive() )
     {
   StopTimer();
     }
}
else {
if ( !iPeriodic->IsActive() )
             {
         StartTimer();
             }
}
}

void CprovaContainer::StartTimer()  {
   const TInt tickInterval=1000000;

  // iPeriodic->Start(tickInterval,tickInterval,TCallBack(CNsTorchContainer::Tick, this));
   iPeriodic->Start(tickInterval,tickInterval,TCallBack(Tick, this));
   }


void CprovaContainer::StopTimer()
  {
  iPeriodic->Cancel();
  delete iPeriodic;
  iPeriodic = NULL;
  }

TInt CprovaContainer::Tick(TAny* aObject)
  {
  // call non-static method
// ( static_cast<CNsTorchContainer*>( aObject ) )->BackLight();
  ((CprovaContainer*)aObject)->MenuGenerate();
  // Allow the timer to continue itÕs work
  return 0;
  }

void CprovaContainer::MenuGenerate()
  {
     CWindowGc& gc = SystemGc();
    gc.BitBlt( Rect().iTl,iBitmap );
  gc.BitBlt(TPoint(0,0), iBitmap);
  }

void CprovaContainer::ReDraw() const {
this->DrawNow();
}

The Function redraw is called from HandleCommandL in the view file.

At the beginning the timer is not started... it start when i prezz Ok Button... but it doesn't create the full screen and nothing more
Thu, 2005-03-31 10:21
Joined: 2005-03-20
Forum posts: 24
CPeriodic Error
I've also tried to keep the const for the updatedisplay and the draw...

calling the starttimer directly from the HandleCommandL in the view file... but the program crashes Cheezy
Thu, 2005-03-31 10:22
Joined: 2004-07-28
Forum posts: 1379
CPeriodic Error
Draw must be const.  It's a virtual function declared as IMPORT_C virtual void Draw(const TRect& aRect) const;.  If you change it to virtual void Draw(const TRect& aRect), it's not the same function - and the framework wont call your overrided Draw to draw the container - instead, it will call it's own implmentation which does nothing.

Generally, Draw should draw the display and do nothing else - which is why it's const.

Best, do it like this:

Code:

void CprovaContainer::Draw(const TRect& aRect) const
{
UpdateDisplay(aRect);
}


void CprovaContainer::UpdateDisplay(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(iBackgroundColor);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}

void CprovaContainer::StartTimer()  {
const TInt tickInterval=1000000;

// iPeriodic->Start(tickInterval,tickInterval,TCallBack(CNsTorchContainer::Tick, this));
iPeriodic->Start(tickInterval,tickInterval,TCallBack(Tick, this));
}


void CprovaContainer::StopTimer()
{
iPeriodic->Cancel();
delete iPeriodic;
iPeriodic = NULL;
}

TInt CprovaContainer::Tick(TAny* aObject)
{
// call non-static method
// ( static_cast<CNsTorchContainer*>( aObject ) )->BackLight();
((CprovaContainer*)aObject)->MenuGenerate();
// Allow the timer to continue itÕs work
return 0;
}

void CprovaContainer::MenuGenerate()
{
CWindowGc& gc = SystemGc();
gc.BitBlt( Rect().iTl,iBitmap );
gc.BitBlt(TPoint(0,0), iBitmap);
}

void CprovaContainer::ReDraw()
{
if(this->status != 5)
{
if(iPeriodic->IsActive())
{
StopTimer();
}
}
else
{
if(!iPeriodic->IsActive())
{
StartTimer();
}
}
DrawNow();
}


didster

  • Login to reply to this topic.