I had the same issues as described in this thread and finally found a solution for this problem. The trick is to use an asynchronous callback in order to create the dialog on startup from the correct context. Well, here we go:
Add following to your AppUi or View header file, whereever you like:
Code:
// Creates and runs the dialog.
TInt OnShowDialog();
// Invoked by async. callback. Forwards call to "OnShowDialog" to get out of the static class scope.
static TInt StaticOnShowDialog(TAny* aPtr);
// Asynchronous callback (CActive, one-shot).
CAsyncCallBack* iAsyncCb;
In the implemenation you have to do following on startup of your AppUi/view:
Code:
TCallBack cb(MyClass::StaticOnShowDialog, this); // We're passing the "this" pointer here, we'll use it later in the static callback.
iAsyncCb = new (ELeave) CAsyncCallBack(cb, CActive::EPriorityStandard);
// Enqueus the callback in the active scheduler.
iAsyncCb->CallBack();
The active scheduler will enqueue the asynchronous callback and invoke the class method "StaticOnShowDialog" of your class from the proper context:
Code:
TInt MyClass::StaticOnShowDialog(TAny* aPtr)
{
// The given pointer is the object pointer to MyClass, so we can cast it safely.
return static_cast<MyClass*>(aPtr)->OnShowDialog();
}
Finally, in the method "OnShowDialog()" you can create your dialog:
Code:
TInt MyClass::OnShowDialog()
{
// Create and run the dialog ...
}
flokrates