Namespaces
Variants
Actions

Listening for Symbian Window Server events in Qt

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia 5800 XpressMusic

Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition

Article
Keywords: QApplication, TWsEvent, RWsSession, TApaTaskList, TApaTask
Created: tepaa (26 Mar 2009)
Last edited: hamishwillee (30 May 2013)

Contents

Overview

This code snippets shows how a Qt application listens for native Symbian TWsEvent window server events.

Preconditions

Send a message

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

The Qt application listens for TWsEvent window server events. Derive QApplication and implement the base class s60EventFilter() method to listen for window server events. In this case we listen for EEventMessageReady 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

The events have been sent and received.

This page was last modified on 30 May 2013, at 09:38.
133 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved