Slider::Listener help, can't add a Slider Listener


#1

Hey Guys,
im new in C++ and Juce.
Can you help me, cause i stuck trying building a simple Window with Userinterface to Calculate some Numbers.

I start off with a new Project form Projucer and say Gui Application.
I want a simple Slider that does something when its changed.
Here is my Code:

Main.cpp (is unchanged, just the Original from the Autocreated File from Projucer.
Main.cpp (3.9 KB)

Here the MainComponent.h
Added the public Slider::Listener Class
The Void function with override
And in the private Section my Variables, included the Slider verbrauchInput; which is the Slider i want to make a Listener.
MainComponent.h (1.1 KB)

And here the MainComponent.cpp
Added here the Variables and the function for the sliderValueChanged (which is still empty, but should not the Problem right?
MainComponent.cpp (1.7 KB)

If i try to build this it gives me following Errors:

Can you guys help me?

Cause in the Basic tutorials from the Juce Website, they allways work without a Headerfile, and include the Slider::Listener directly in the MainComponent.cpp

That works with no Bugs in my System as well.

Working on Mac OSX 10.11.6 , XCode 7.2

Appreciate Tips and Tricks, and hope you can help me.

Sorry about my English, im native German.

Greetings,
Manuel


#2

The implementation of the Slider::Listener callback doesn’t match the version in the header.
Furthermore it is not in the classes namespace.

Add MainContentComponent:: before sliderValueChanged, and the argument has to be a pointer, not a reference, just as specified in the header:

void MainContentComponent::sliderValueChanged (Slider *verbrauchInput)

HTH


#3

AWESOME!

so if i add a Listener in the Headfile, i need to tell in the cpp file in which Class to find the function, in that case the ine MainContentComponent - Class, right?

Works for now, thank you very much!


#4

Has nothing to do with inheriting from / implementing the SliderListener… Also not in which class to find the function, it’s about in which class to fill in the function. The header file just ‘declares’ it, like, this is going to exist and do something in the final program. The .cpp side gives the function its true content, behaviour. The header is just the skeleton (‘signature’). Because the .cpp file is quite loose from the .h file, one will need to scope everything in there with the class name. Very easy to make this mistake and also not easy to get from the error messages that this is what was wrong. It helps to try and have a strict way of copy pasting the function and then putting the class scope immediately in the .cpp.


#5

Hey Chamabreu, here’s a video on the Slider and Slider::Listener class that I’ve done that may help. https://youtu.be/pTJYowGub6o


#6

Nice,

Thank you guys.
@JoshuaHodge, watched already some of your Videos Last week.
I will rewatch your listener-Video, Maybe now its more understandable!!

Thanks