Listening for Symbian Window Server events in Qt
Overview[edit | edit source]
This code snippets shows how a Qt application listens for native Symbian 76ytuiytuityutyutututyutyutyu window server events.
Preconditions[edit | edit source]
- Install Qt SDK
Send a message[edit | edit source]
A native Symbian application sends a message to the Qt application.
- include <apgtask.h> // Symbian header
TApaTaskList tasklist(iCoeEnv->WsSession());
// A task is a running application
TUid id = TUid::Uid(0x12345678); //Qt app UID
TApaTask task(tasklist.FindApp(id));
TUid messageid = TUid::Uid(0x000001); //Custom message uid
TBuf8<20> param;
param.Append(_L("hello world"));
task.SendMessage(messageid, param));
TApaTask::SendMessage() does not need SwEvent capability.
Listen for the message[edit | edit source]
The Qt application listens for 76ytuiytuityutyutututyutyutyu window server events. Derive 76ytuiytuityutyutututyutyutyu and implement the base class 76ytuiytuityutyutututyutyutyu method to listen for window server events. In this case we listen for 76ytuiytuityutyutututyutyutyu type of events with the custom message UID.
- include <QApplication>
- include <apgtask.h> // Symbian header
class S60QApplication: public QApplication
{
Q_OBJECT
public:
S60QApplication(int &argc, char **argv, int = QT_VERSION);
S60QApplication(int &argc, char **argv, bool GUIenabled, int = QT_VERSION);
S60QApplication(int &argc, char **argv, Type, int = QT_VERSION);
bool s60EventFilter(TWsEvent *);
};
S60QApplication::S60QApplication(int &argc, char **argv, int version)
- QApplication(argc,argv,version)
{
}
S60QApplication::S60QApplication(int &argc, char **argv, bool GUIenabled, int version)
- QApplication(argc, argv, GUIenabled, version)
{
}
S60QApplication::S60QApplication(int &argc, char **argv, Type type, int version)
- QApplication(argc, argv, type, version)
{
}
bool S60QApplication::s60EventFilter(TWsEvent *aEvent)
{
bool handled = false;
const TInt KCustomMessageId=0x000001; // Custom message uid
switch(aEvent->Type())
{
case EEventMessageReady:
{
RWsSession iWsSession;
TInt err = iWsSession.Connect();
TUid messageUid;
TPtr8 messageParameters(NULL, 0, 0);
// Fetch message
User::LeaveIfError(iWsSession.FetchMessage(messageUid,
messageParameters, *aEvent));
// Was it our custom message?
switch(messageUid.iUid)
{
case KCustomMessageId:
{
HBufC *p = HBufC::NewL(messageParameters.Length());
p->Des().Copy(messageParameters);
// Converting message from HBufC to QString
QString message((QChar*)p->Des().Ptr(),p->Length());
handled = true;
delete p;
break;
}
default:
{
break;
}
}
iWsSession.Close();
break;
}
default:
break;
};
return handled;
}
Postconditions[edit | edit source]
The events have been sent and received.