Multiview, call view's function from others

Login to reply to this topic.
Tue, 2007-01-30 12:44
Joined: 2005-06-04
Forum posts: 131
Hi all,
I have 4 views in tabgroup, and a menu shown by all views. The menu's command handler is in separete file.

commandhandler.cpp:

TBool CommandHandler(TInt aCommand, CkeretAppUi* AppUi) {
  TBool res=ETrue;
  TFileName drvName;
  switch (aCommand) {
    case ECmd1:
      ...
    break;
    case ECmd2:
      ...
    break;
[...]
    default:
      res=EFalse;
    break;
  }
  return res;
}

I call it from view:

void CkeretView1::HandleCommandL(TInt aCommand)
    {
       switch (aCommand) {
         case EkeretSpecItem:
          iView->Search();
         break;
         default:
           if (!CommandHandler(aCommand,(CkeretAppUi*)AppUi())) {
             AppUi()->HandleCommandL(aCommand);
           }
         break;
       }
    }

My problem: I need to reach a function in view1 from all views. In commandhandler.cpp I tried this:

// shitch tabgroup
      AppUi->iTabGroup->SetActiveTabByIndex(1);
      AppUi->ActivateLocalViewL(TUid::Uid(EkeretView1Id));
// call function
      ((CkeretView1*)(AppUi->View(TUid::Uid(EkeretView1Id))))->iView->Search();

it crash before entering Search() function.

      ((CkeretView1*)(AppUi->View(TUid::Uid(EkeretView1Id))))->Search();

in view:
void CkeretView1::Search() {
  iView->Search();
}

This way it enters Search() function and crash inside!?!?

Any idea how can I call a view's (viewcontainer's) function from other views?

Thanks

Wed, 2007-01-31 08:28
Joined: 2006-05-10
Forum posts: 64
Re: Multiview, call view's function from others
Hi,

  It is common, that view's container object (in your case iView) is created in DoActivateL method and deleted in DoDeactivate. So, probably you have other view activated and View1's iView object doesn't exist.
  I would recommend that if you have some method, that should be accessed from all the views, move it into different class like AppUi or create a separate class owned by your AppUi. The easiest solution is not delete the container (iView) object in DoDeactivate (create it in ConstructL and delete in destructor), but I don't recommend that.

Regards,
  Damian

Confusion will be my epitaph..

  • Login to reply to this topic.