cancel
Showing results for 
Search instead for 
Did you mean: 

Resolved: How to implement an event callback?

mandrake
Senior

I am not a C++ programmer but learning quickly. I made good progress integrating TouchGFX 4.13.0 with STM32CubeIDE 1.2.1. Platform is STM32F746G-Discovery.

I created my own thread and that is working. Now I simply want to implement a button callback function. I have a button on Screen2 and I called the callback function Test_Button_Callback( ). I created the following code and placed it into a file named myClass.cpp

#include <gui_generated/screen2_screen/Screen2ViewBase.hpp>

#include <gui/screen2_screen/Screen2Presenter.hpp>

class Screen2View : public Screen2ViewBase

{

public:

  void Test_Button_Callback()

  {

  int count;

  count++;

  }

};

The code compiles and loads. The debugger indicates that my function is "shadowing" the base function, whatever that means.

I am missing something on how to override the Screen2ViewBase virtual function. I can follow the execution in debug but it is not getting to my code.

I obviously do not know what I am doing. I have searched numerous examples and documentation and nothing helped and my head is spinning. Any help will be appreciated.

3 REPLIES 3
mandrake
Senior

After a lot of trials and errors I think I have figured it out.

I created two files Screen2View.hpp and Screen2View.cpp

Screen2View.hpp

#ifndef SCREEN2VIEW_HPP

#define SCREEN2VIEW_HPP

#include <gui_generated/screen2_screen/Screen2ViewBase.hpp>

#include <gui/screen2_screen/Screen2Presenter.hpp>

class Screen2View : public Screen2ViewBase

{

public:

  virtual void Test_Button_Callback();

};

#endif // SCREEN2VIEW_HPP

Screen2View.cpp

#include <gui/screen2_screen/Screen2View.hpp>

void Screen2View::Test_Button_Callback()

{

// my code here

}

Martin KJELDSEN
Chief III

Hi @mandrake​,

You figured it out or just think you did? Let me know 🙂 I'm back from vacation to help!

/Martin

Hi Martin,

Thanks for helping. You are right - I don't really know what I am doing and it would be nice to know what is happening.

I created two files Screen2View.hpp and Screen2View.cpp. Do these filenames matter?

As I understand it I need to implement the virtual function of the base class Screen2ViewBase. This can be overridden by creating a derived class such as Screen2View. Where is Screen2View ever being invoked? Why can I not simply create the implementation of my Test_Button_Callback( ) and where does this go if this is possible?

I extended my Screen2 by adding two new buttons with similar interaction as the first Test_Button.

One new button has the green up-arrow in debug indicating that it is overriding the base function. Yet it is not being called.

The second new button does not show the green arrow and it too is not being called.

Very confusing and frustrating.

In examples I have looked at what do these two lines below do:

  Screen2View();

  virtual ~Screen2View() {}

#ifndef SCREEN2VIEW_HPP

#define SCREEN2VIEW_HPP

#include <gui_generated/screen2_screen/Screen2ViewBase.hpp>

#include <gui/screen2_screen/Screen2Presenter.hpp>

class Screen2View : public Screen2ViewBase

{

public:

  Screen2View();

  virtual ~Screen2View() {}

  virtual void setupScreen();

  virtual void tearDownScreen();

  virtual void Test_Button_Callback();

  virtual void Quit_Button_Callback();

  virtual void Cancel_Button_Callback();

protected:

};

#endif // SCREEN2VIEW_HPP