Symbian
Symbian OS Library

FAQ-0886 Why should a derived App Ui's ConstructL() function use BaseConstructL() sometimes, instead of ConstructL()?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Application Architecture
Created: 06/25/2003 Modified: 03/10/2004
Number: FAQ-0886
Platform: Symbian OS v6.1, Symbian OS v7.0, Symbian OS v7.0s

Question:
What is the difference in calling CxxxAppUi::ConstructL() and CxxxAppUi::BaseConstructL() from a derived class, in UIQ and Series60

Answer:
In deriving an AppUi class from either CAknAppUi (Series 60) or CQikAppUi (UIQ), one comes across the following inconsistency

case 1 - "Constructing of a UIQ AppUi"
[CxxxAppUi is derived from CQikAppUi]
void CxxxAppUi::ConstructL()
{
   CQikAppUi::ConstructL();
   ...
}

case 2 - "Constructing of a Series 60 AppUi"
[CxxxAppUi is derived from CAknAppUi]
void CxxxAppUi::ConstructL()
{
   BaseConstructL();
   //CAknAppUi::ConstructL() - does not work here!?
   ...
}

CEikAppUi and CQikAppUi offer ConstructL() so that they can have the option to do a bit more work in construction before calling BaseConstructL(). In CEikAppUi and CQikAppUi, their ConstructL() will infact call their BaseConstructL() eventually.

However, in the Series 60 UI, CAknAppUi only defines a BaseConstructL() method and does not provide a corresponding version of ConstructL(). Therefore, using the form:

void CMyOwnAppUi::ConstructL()
{
CAknAppUi::ConstructL();
iAppView = CHelloGuiAppView::NewL(ClientRect());
}

will fail to correctly construct the Series 60 App UI.

Calling BaseConstructL() from a derived class is essential for the Series 60 interface, since calling ConstructL() in that case would result in calling CEikAppUi::BaseConstructL() (from which it derives), thus missing the CAknAppUI::BaseConstructL().

Nevertheless, this does not mean, that when one designs a new CxczAppUi, one shouldn't make use of a CxczAppUi::ConstructL(). It is actually recomended that one should, so that any specific initialisation that does not deal purely with base construction can be encapsulated there.