cancel
Showing results for 
Search instead for 
Did you mean: 

Can't include external c/h files into View without compilation error

ilyus
Senior II

Windows 10, TouchGFX Designer 4.17, CubeIDE 1.6.1

I'm trying to make custom elements on my screen, not created through the Designer. So, for every screen the designer creates ViewBase and View files. I want to have other files for the screen where I will have more definitions and functions, because I don't want to have a View file of 2000 lines, it gets impossible to work with.

I want to separate stuff and include these files into the View file. So that my variables are declared in several header files and so are the functions that declare or draw stuff or have callbacks and stuff. My ideal is to have a subfolder in the screen file with more .c/.cpp/.h/.hpp files in there, which are included into the View file, so I can call functions from those files while on screen.

Except that nothing I do compiles, and I don't really have any clue about how to include those, if I fix one error, another one shows up.

The screen in TouchGFX designer is ENTIRELY EMPTY. In the View files, I only want to include MyCustomFiles and maybe call their functions. Yeah, I don't know how to include a file properly, just great.

So, here is what I have:

ViewBase.hpp/cpp are pristine unchanged, only generates background box and nothing else, the screen is empry

Now, my new custom files I'm adding are the following:

measurementBoxGenerator.hpp:

#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/widgets/BoxWithBorder.hpp>
#include <touchgfx/containers/ScrollableContainer.hpp>
#include <touchgfx/widgets/TextArea.hpp>
#include <touchgfx/widgets/TextAreaWithWildcard.hpp>
#include <touchgfx/widgets/Button.hpp>
#include <touchgfx/Color.hpp>
#include <texts/TextKeysAndLanguages.hpp>
#include "BitmapDatabase.hpp"
#include <touchgfx/containers/buttons/Buttons.hpp>
#include <touchgfx/containers/scrollers/ScrollWheel.hpp>
#include <touchgfx/utils.hpp>
#include <string>
 
#include <gui_generated/screenmeasurement_screen/ScreenMeasurementViewBase.hpp>
#include <gui/screenmeasurement_screen/ScreenMeasurementPresenter.hpp>
 
class measurementBoxGenerator: public ScreenMeasurementViewBase {
public:
	measurementBoxGenerator();
	virtual ~measurementBoxGenerator() {
	}
	virtual void myfunction();
	static const uint16_t NUMBER_OF_MEASUREMENTS = 40;
	touchgfx::BoxWithBorder measurementBox[NUMBER_OF_MEASUREMENTS];
 
 
 
protected:
};

and its buddy measurementBoxGenerator.cpp:

#include <gui/screenmeasurement_screen/measurementBoxes/measurementBoxGenerator.hpp>
 
measurementBoxGenerator::measurementBoxGenerator()
{
	measurementBox[0].setPosition(0, 0, 190, 200);
	//rest to be added later
	add(measurementBox[0]);
	touchgfx_printf("external file included");
 
}
void measurementBoxGenerator::myfunction(){
	touchgfx_printf("external file included; myfunction called");
}

I'm actually trying to make these two files do anything at all. Well, just compile at first, actually.

These custom files are included in the View files, which look like that:

View.hpp:

completely unchaged from default.

The one and only addition so far is

#include <gui/screenmeasurement_screen/measurementBoxes/measurementBoxGenerator.hpp>

including my first custom header file. This line of code compiles OK.

In View.cpp, I have added 2 lines of code:

void ScreenMeasurementView::setupScreen()
{
    ScreenMeasurementViewBase::setupScreen();
    measurementBoxGenerator test;
    test::myfunction();
}

Problems start on line "measurementBoxGenerator test;" This line doesn't compile and says some stuff like "test is not a class, namespace or enumeration" (I've been creating objects like this all my life and now it's suddenly an error for whatever magical reason, great!)

If I do

    measurementBoxGenerator test =  measurementBoxGenerator();
    test::myfunction();

It also spits out compilation error and suggests *test instead of test. I have also no idea why as everything in my life worked without pointers in this kind of declarations.

Alright, let's say I do what it suggests, so now I have *test and compilation crashes on the next line saying that it can't convert non-pointer to pointer. OK, so I replaced test::myfunction(); with *test... or &test and it still can't convert stuff and spits errors. I tried adding "new" before measurementBoxGenerator(), it doesn't change anything at all. I can put asterisks and ampersands before "test" in all combinations, it doesn't work.

The question is: what is going on? Why all my life all declarations worked, and now they suddenly don't? How can I connect another file into the screen's view file and run functions from it? (including drawing stuff).

0 REPLIES 0