setTooltip() crashes

Hi
I’m using a common class for 2 other classes as follow:

class RouterCommon : public juce::Component, public juce::Button::Listener {}

class RouterMidi : public RouterCommon {}
class RouterAudio : public RouterCommon {}

In MainComponent:

juce__tabbedComponent->addTab ((“MIDI Router”), juce::Colours::lightgrey, new RouterMidi (), true);
juce__tabbedComponent->addTab ((“Audio Router”), juce::Colours::lightgrey, new RouterAudio (), true);

The UI is defined in RouterCommon. When using setTooltip() from a component in RouterCommon, the app crashes at runtime with the following from juce_TooltipWindow:

// Looks like you have more than one TooltipWindow showing the same tip.
// Be careful not to create more than one instance of this class with the
// same parent component!
jassertfalse;

I searched over the forum, without success so far, any help would be appreciated.
Thanks

The jassert is quite clear. Do you declare juce::TooltipWindow as a class member of RouterCommon?

I tried to add this as a private class member yes then init with ‘this’ in the constructor but it did not help

The weird thing is that all tooltips crash the app also the ones from the components that are not related to those mentioned classes.

It works only if I comment one of the two classes declared in the main component, when I add them to the tab bar.

It seems that I haven’t made it clear. Because the two RouterMidi and RouterAudio share the same parent (MainComponent), you should move the tooltip window as a member of MainComponent instead. See what jassert says:

Be careful not to create more than one instance of this class with the same parent component!

Thanks

Ok I can try to add a tooltip member in the main component, initialize it with ‘this’, then I should pass a reference to this tooltip to the children routerAudio and routerMidi ? Is this the way to solve this issue ?

I should not be alone to use tooltips on a child component sharing a class with another one

I don’t quite understand the problem. Why do you need the children to hold a reference to juce::TooltipWindow in this first place?

As @zsliu98 mentions, it’s not clear why you think you need to do extra work. For basic usage, you just put a juce::TooltipWindow as a member of the top of the hierarchy, and then call setToolTip on any component in that hierarchy and tool tips just work.

Are your questions from a need to do something special, or possibly you have just misunderstood how the tool tip system works?

Thanks for your help.
It works now, I just found another instance of tootipWindow declared somewhere in a child !

1 Like