CPeriodic Error
| Wed, 2005-03-30 20:53 | |
|
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? ![]() |
|







Forum posts: 33
the method want a void pointer and you give him a integer reference.
try to cast to tany*, e.g.
(TAny*) &tickValue
Forum posts: 24
this is the example present in the .chm file of the dsk.
{
// 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;
}
Forum posts: 140
Paul Todd
Forum posts: 24
Anyway... tnx a lot Paul
Sorry for the disturb.
Forum posts: 1379
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
didster
Forum posts: 24
the code is the same of the other pc....same sdk...same compiler
{
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 ?
Forum posts: 24
Now to solve the problem i had to modify it to
So my question is... why with this notebook i have to change the source code?
Forum posts: 1379
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
Forum posts: 1379
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
Forum posts: 24
Tnx for the answer. Very polite
Forum posts: 24
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...
Forum posts: 1379
Have you put a break point in UpdateDisplay? Does it even get called?
didster
Forum posts: 24
{
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
Forum posts: 24
calling the starttimer directly from the HandleCommandL in the view file... but the program crashes
Forum posts: 1379
Generally, Draw should draw the display and do nothing else - which is why it's const.
Best, do it like this:
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