Skip to main content
Senior
June 30, 2025
Solved

Touchgfx - virtual methods in the "final" Screen class

  • June 30, 2025
  • 1 reply
  • 337 views

Hello, I need to use Touchgfx on a small CPU and I'm optimizing my code accordingly. However, in the code that Touchgfx Designer generates, I noticed something that I don't understand:
The Screen classes inherit from the ScreenBase classes.
The Screen classes are actually final, but they have virtual functions, which makes the compiler generate virtual tables for them. The same goes for the Listener classes. Does anyone have any ideas on this?
Best regards

Best answer by GaetanGodart

Hello @Panchev68 ,

 

When you add a screen, there will be a screenViewBase cpp and hpp files created with virtual functions but also a ScreenView cpp and hpp file.
You should not modify the base file as they get regenerated, instead you should overwrite the virtual functions by adding code in the ScreenView files (not the base files).

Is the extra computation required to look at the function table really that impactful? I don't think so, we have been able to design GUI using STM32G0 already (but without FreeRTOS).

 

Regards,

1 reply

GaetanGodart
GaetanGodartBest answer
Technical Moderator
July 2, 2025

Hello @Panchev68 ,

 

When you add a screen, there will be a screenViewBase cpp and hpp files created with virtual functions but also a ScreenView cpp and hpp file.
You should not modify the base file as they get regenerated, instead you should overwrite the virtual functions by adding code in the ScreenView files (not the base files).

Is the extra computation required to look at the function table really that impactful? I don't think so, we have been able to design GUI using STM32G0 already (but without FreeRTOS).

 

Regards,

Panchev68Author
Senior
July 2, 2025

10 screens ~ -2Kb 

I'm asking out of simple human curiosity. I hope I missed something in C++. This solution plus a few others worked for me.
Congratulations on the wonderful environment you provide.
Best regards