Adding components to existing components at runtime


#1

Dear forum

I’m trying to create and add components to my gui at runtime.

Component* new_c = new Component(); Component* c = this->getActiveEditor(); c->addChildComponent(new_c);
(toy example)

If I do this for example in the processBlock the debugger halts in the Component::getPeer() method because of a access violation.

If anybody could give me a hint what I’m missing here, I would be very thankfull.

Kind regards
oliver


#2

is getActiveEditor returning nullptr?


#3

Yes it does return a nullptr. But I have a PluginEditor and its window is showing as I want it.

Thanks for the answer


#4

You shouldn’t do it that way, as you can not be sure that you actually have an editor. Instead you should set a flag in the processor and have it checked regularly by the editor ( which then adds the component to itself if necessary).


#5

I just found out that an editor only exists when the user opens it (documentation AudioProcessor::createEditor ()). Shame on me!
I’m gonna do siedschl’s way.

Thank you very much!