Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jan 2008

    Question How to handle events (e.g. button click)

    Hi there,

    happy new year :)

    i am new to this whole symbian os programming stuff and recently got started with it so dont kill me if i ask something stupid :).

    ok heres the issue. because i am new to this stuff i want to create an application that simply handles a button click. so i digged in the uiq developer reference for words like "event", "click", "pointer" and so on. i came to the conclusion that a "button click" has to be a window server event. is that right?

    my code looks pretty simple but the RunL() function that should be called when a event occures isnt called at all. i dont know why. i have written the following lines:

    //first i declared my own class derived from CActive
    class CNewClass : public CActive
    // in the ConstructL functuion that is called from NewL / NewLC 
    // i connect to the window server
    void CNewClass::ConstructL()
     CActiveScheduler::Add( this );
    // Request window server events
    void CNewClass::IssueRequest()
     iWs.EventReady(&iStatus); // request an event
     SetActive(); // now active
    //the RunL method
    void CNewClass::RunL()
     //here comes a few lines setting the text of a button to a
     //value of a counter variable, its my way to see wether the
     //RunL() is called or not
     //request further events
    I create an instance of the class when i click a menu entry.

    I think this i how the howto describes it in the UIQ developer reference. So why is RunL() not called? (please dont answer with a link to the SDK SymbianNotCompatible\Graphics\WS\Simple example because it doesnt work, it crashes when i start the emulator and also it crashes on my P1i)

    Another question. I dont really understand how the scheduler can call a RunL() method of an CActive object when i didnt pass an reference of my object on requesting an event? This totally confuses me because there are a sample where a timer is created to get a periodically event (e.g. each 1 second), but the timer is created just like this without any reference to anything but this sample works on my machine ?!?.

    I hope you understand what i want to say.

    Thx in advance for helping.
    Last edited by ViRuSTriNiTy; 2008-01-02 at 20:34.

  2. #2
    Registered User
    Join Date
    Oct 2005

    Re: How to handle events (e.g. button click)


    Before calling EventReady(&iStatus) you need to enable events you want to capture. This via RWindowGrop::CaptureKey. I assume your application is not a UI application since you need to capture keys via window server. Thus, you need to create a window group also.

  3. #3
    Registered User
    Join Date
    Jan 2008

    Re: How to handle events (e.g. button click)


    sorry but its an UI application. i began from scratch wirh a simple uiq UI appllication c++ project. i also dont want to capture key strokes at the moment, i want to get an button click event. the button is clicked via the touchscreen of my P1i.

    any ideas?

    thx in advance.


    i followed a hint with HandlePointerEventL and i came to an solution. this solution is not state of the art i think but useable for me. by throwing away the active object idea and overriding the event handler method i can now handle a button click this way:

    // i simply override the event handler method in my view to get a pointer event of my touchscreen
    void CTestView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
     if (aPointerEvent.iType == TPointerEvent::EButton1Up)
      CEikTextButton* button = LocateControlByUniqueHandle<CEikTextButton>(ETestButtonCtrl);
      if (button->Rect().Contains(aPointerEvent.iPosition))
    You can see how i determine which control was clicked. I ask myself, isnt there a better way to do this? Lets imagine a view that has a huge amount of buttons. In this view i have to loop over this->Controls() to get the control that was clicked. in other programming languages i can use ControlFromPoint() or something like that to determine the control at the specific point. Isnt there a function in symbian c++?

    Second question is, how can i "override" the HandlePointerEventL method of my button? In other languages like delphi i do something like

    button.HandlePointerEventL = MyEventHandlerMethod;

    When i do this in symbian c++ i get an error message that i fogot a "&" which is true in this case, but when i insert a & in front of MyEventHandlerMethod i get an error that in ISO C++ i cannot do this. Whats the trick here?

    Perhaps i should create a new class derived from a button class and then override the method. But again, here i dont get a clue how to insert a button with my own class in the resource file.

    i also found a way to handle a button click with a command button (it also works with other button types i think) and without using coordinates. just override the HandleControlEventL() method of the view. heres my solution (the example shows a click handler that toggles the dimmed state of the button):

    void CTestView::HandleControlEventL(CCoeControl *aControl, TCoeEvent aEventType)
      case EEventStateChanged:
      case EEventInteractionRefused:
       if (aControl->UniqueHandle() == ETestButtonCtrl3) 
        CEikCommandButton* b = LocateControlByUniqueHandle<CEikCommandButton>(ETestButtonCtrl3);
        TBool d = !b->IsDimmed();
       CQikViewBase::HandleControlEventL(aControl, aEventType);
    Thx for helping.


    i finally managed to achieve my goal by rethinking the idea of creating a own class for my button (thx to sander for guiding me to the correct path). here are the steps:

    1. define a new class for your button derived from e.g. CEikTextButton
    2. override HandlePointerEventL() and handle your stuff in here
    3. create an instance of the button in ViewConstructL() of a view

    now we have 3 solutions . anyway, if somebody can explain one of the things mentioned in this thread:

    1. how i can assign a event handler to an existing button object
    2. how can the active scheduler call a RunL() method of an CActive object when no reference of the concering object is passed on requesting an event

    thx for helping.
    Last edited by ViRuSTriNiTy; 2008-01-02 at 22:05.

Similar Threads

  1. Replies: 2
    Last Post: 2007-09-27, 07:45
  2. how to handle handle two events simultaniusly
    By j2me_raj in forum Symbian C++
    Replies: 2
    Last Post: 2007-06-06, 03:22
  3. Debugging Symbian S60 with Carbide C++ Express and NCF 1.2 Bluetooth
    By jimgilmour1 in forum Bluetooth Technology
    Replies: 4
    Last Post: 2006-09-05, 19:30
  4. Nokia 7710: how to simulate button click?
    By sim.sim in forum Symbian C++
    Replies: 0
    Last Post: 2006-05-18, 15:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts